这题,关键不是二分,而是如果在t的时间内,将n个头,刷完这m个磁盘。
看了一下题解,完全不知怎么弄。用一个指针从pre,枚举m,讨论一下。只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的之前刷了)。
思维是硬伤。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL __int64
LL p[],h[];
int n,m;
int judge(LL x)
{
int pre = ;
LL temp;
int i;
for(i = ;i < n;i ++)
{
if(abs(p[pre]-h[i]) > x) continue;
if(p[pre] < h[i])
temp = h[i] + max((x-(h[i]-p[pre]))/,x-*(h[i]-p[pre]));
else
temp = h[i] + x;
while(p[pre] <= temp&&pre < m)pre ++;
}
if(pre == m)
return ;
else
return ;
}
LL bin()
{
LL str,end,mid;
str = ;
end = 100000000000000ll;
while(str < end)
{
mid = (str + end)/;
if(judge(mid))
end = mid;
else
str = mid + ;
}
return str;
}
int main()
{
int i;
scanf("%d%d",&n,&m);
for(i = ;i < n;i ++)
{
scanf("%I64d",&h[i]);
}
for(i = ;i < m;i ++)
{
scanf("%I64d",&p[i]);
}
printf("%I64d\n",bin());
return ;
}