交CF题出现了这个故障:
Probably, the solution is executed with error 'shift too large' on the line 26
有没有大佬帮忙看看 CF343C
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,m,ans,l=0,r=1e10,p[N],h[N];
inline bool check(int t)
{
int x=1;
for(int i=1;i<=n;i++)
{
if(h[i]<p[x])
{
while(x<=m&&p[x]-h[i]<=t)
{
x++;
}
}
else
{
if(h[i]-p[x]>t)
{
return false;
}
int dis=h[i]-p[x];
while(x<=m&&(p[x]-h[i]<=t-(dis<<1)||(p[x]-h[i])<<1+dis<=t))
{
x++;
}
}
if(x>m)
{
return true;
}
}
return false;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>h[i];
}
for(int i=1;i<=m;i++)
{
cin>>p[i];
}
while(l<=r)
{
int mid=l+r>>1;
if(check(mid))
{
r=mid-1;
ans=mid;
}
else
{
l=mid+1;
}
}
cout<<ans;
exit(0);
}