#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+55;
long long sum[N];
long long pos[N];
int n;
bool ok(int x, long long b)
{
long long best,cur;
best=1e18+55;
for(int i=0;i<=n-x;i++)
{
// cur=pos[x/2+i]*(x/2)-sum[i+x/2-1];
// if(i)
// cur+=sum[i-1];
// cur+=sum[i+x-1]-sum[i+(x-1)/2]-pos[x/2+i]*(x/2);
cur=0;
for(int j=i;j<i+x;j++)
{
cur+=abs(pos[j]-pos[i+(x-1)/2]);
}
best=min(best,cur);
}
if(best>b)
return 0;
return 1;
}
int besthub(int N, int L, int X[], long long B)
{
n=N;
for(int i=0;i<n;i++)
{
pos[i]=X[i];
sum[i]=X[i];
if(i)
sum[i]+=sum[i-1];
}
int l=1;
int r=n;
int mid;
while(l<r)
{
mid=(l+r)/2;
if(ok(mid,B))
l=mid+1;
else
r=mid;
}
return l-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
3 ms |
516 KB |
Output is correct |
5 |
Correct |
3 ms |
516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
572 KB |
Output is correct |
2 |
Correct |
3 ms |
572 KB |
Output is correct |
3 |
Incorrect |
3 ms |
572 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
572 KB |
Output is correct |
2 |
Correct |
3 ms |
572 KB |
Output is correct |
3 |
Incorrect |
4 ms |
572 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
1084 KB |
Output is correct |
2 |
Correct |
428 ms |
1084 KB |
Output is correct |
3 |
Execution timed out |
1083 ms |
2536 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |