#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/2]);
}
best=min(best,cur);
// 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=2;
int r=n+1;
int mid;
while(l<r)
{
mid=(l+r)/2;
if(ok(mid,B))
l=mid+1;
else
r=mid;
}
return l-1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
412 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
3 ms |
668 KB |
Output is correct |
4 |
Correct |
3 ms |
668 KB |
Output is correct |
5 |
Correct |
3 ms |
668 KB |
Output is correct |
6 |
Correct |
2 ms |
668 KB |
Output is correct |
7 |
Correct |
3 ms |
668 KB |
Output is correct |
8 |
Correct |
4 ms |
668 KB |
Output is correct |
9 |
Correct |
3 ms |
672 KB |
Output is correct |
10 |
Correct |
3 ms |
796 KB |
Output is correct |
11 |
Correct |
3 ms |
796 KB |
Output is correct |
12 |
Correct |
3 ms |
796 KB |
Output is correct |
13 |
Correct |
3 ms |
796 KB |
Output is correct |
14 |
Correct |
3 ms |
796 KB |
Output is correct |
15 |
Correct |
3 ms |
796 KB |
Output is correct |
16 |
Correct |
3 ms |
796 KB |
Output is correct |
17 |
Correct |
3 ms |
796 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
3 ms |
796 KB |
Output is correct |
20 |
Correct |
3 ms |
796 KB |
Output is correct |
21 |
Correct |
3 ms |
796 KB |
Output is correct |
22 |
Correct |
5 ms |
796 KB |
Output is correct |
23 |
Correct |
2 ms |
796 KB |
Output is correct |
24 |
Correct |
4 ms |
796 KB |
Output is correct |
25 |
Correct |
5 ms |
800 KB |
Output is correct |
26 |
Correct |
3 ms |
804 KB |
Output is correct |
27 |
Correct |
3 ms |
808 KB |
Output is correct |
28 |
Correct |
5 ms |
812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
816 KB |
Output is correct |
2 |
Correct |
3 ms |
816 KB |
Output is correct |
3 |
Correct |
4 ms |
816 KB |
Output is correct |
4 |
Correct |
4 ms |
816 KB |
Output is correct |
5 |
Correct |
3 ms |
824 KB |
Output is correct |
6 |
Correct |
3 ms |
828 KB |
Output is correct |
7 |
Correct |
5 ms |
832 KB |
Output is correct |
8 |
Correct |
4 ms |
936 KB |
Output is correct |
9 |
Correct |
5 ms |
936 KB |
Output is correct |
10 |
Correct |
5 ms |
936 KB |
Output is correct |
11 |
Correct |
4 ms |
936 KB |
Output is correct |
12 |
Correct |
5 ms |
936 KB |
Output is correct |
13 |
Correct |
4 ms |
936 KB |
Output is correct |
14 |
Correct |
5 ms |
960 KB |
Output is correct |
15 |
Correct |
3 ms |
960 KB |
Output is correct |
16 |
Correct |
5 ms |
960 KB |
Output is correct |
17 |
Correct |
4 ms |
960 KB |
Output is correct |
18 |
Correct |
4 ms |
968 KB |
Output is correct |
19 |
Correct |
4 ms |
968 KB |
Output is correct |
20 |
Correct |
4 ms |
984 KB |
Output is correct |
21 |
Correct |
36 ms |
1084 KB |
Output is correct |
22 |
Correct |
36 ms |
1104 KB |
Output is correct |
23 |
Correct |
34 ms |
1168 KB |
Output is correct |
24 |
Correct |
28 ms |
1204 KB |
Output is correct |
25 |
Correct |
26 ms |
1240 KB |
Output is correct |
26 |
Correct |
26 ms |
1288 KB |
Output is correct |
27 |
Correct |
101 ms |
1324 KB |
Output is correct |
28 |
Correct |
90 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
374 ms |
1660 KB |
Output is correct |
2 |
Correct |
386 ms |
1660 KB |
Output is correct |
3 |
Execution timed out |
1082 ms |
3196 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |