#include "ricehub.h"
#include <bits/stdc++.h>
typedef long long ll;
const int N=100050;
ll sum[N];
int x[N];
ll sm(int l, int r){
return sum[r]-sum[l-1];
}
int besthub(int n, int sz, int D[], ll b)
{
int i;
for(i=1;i<=n;i++){
x[i]=D[i-1];
sum[i]=sum[i-1]+x[i];
}
int r=n,l=1,mid,ans=1;
while(r>=l)
{
mid=(l+r)/2;
bool ok=0;
for(i=mid;i<=n;i++)
{
int L=i-mid+1;
int R=i;
int M=(L+R)/2;
ll cost=(ll)(M-L+1)*x[M]-sm(L,M);
cost+=sm(M,R)-(ll)(R-M+1)*x[M];
if(cost<=b){ ok=1;break;}
}
if(ok) ans=mid,l=mid+1;
else r=mid-1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
368 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
3 ms |
584 KB |
Output is correct |
5 |
Correct |
3 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
584 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
2 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
732 KB |
Output is correct |
12 |
Correct |
3 ms |
732 KB |
Output is correct |
13 |
Correct |
3 ms |
732 KB |
Output is correct |
14 |
Correct |
3 ms |
732 KB |
Output is correct |
15 |
Correct |
3 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
3 ms |
732 KB |
Output is correct |
19 |
Correct |
3 ms |
732 KB |
Output is correct |
20 |
Correct |
3 ms |
732 KB |
Output is correct |
21 |
Correct |
2 ms |
840 KB |
Output is correct |
22 |
Correct |
3 ms |
840 KB |
Output is correct |
23 |
Correct |
3 ms |
840 KB |
Output is correct |
24 |
Correct |
3 ms |
840 KB |
Output is correct |
25 |
Correct |
4 ms |
840 KB |
Output is correct |
26 |
Correct |
2 ms |
840 KB |
Output is correct |
27 |
Correct |
2 ms |
840 KB |
Output is correct |
28 |
Correct |
3 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
840 KB |
Output is correct |
2 |
Correct |
3 ms |
840 KB |
Output is correct |
3 |
Correct |
4 ms |
840 KB |
Output is correct |
4 |
Correct |
3 ms |
840 KB |
Output is correct |
5 |
Correct |
3 ms |
840 KB |
Output is correct |
6 |
Correct |
3 ms |
840 KB |
Output is correct |
7 |
Correct |
3 ms |
840 KB |
Output is correct |
8 |
Correct |
3 ms |
840 KB |
Output is correct |
9 |
Correct |
4 ms |
840 KB |
Output is correct |
10 |
Correct |
3 ms |
840 KB |
Output is correct |
11 |
Correct |
3 ms |
840 KB |
Output is correct |
12 |
Correct |
3 ms |
840 KB |
Output is correct |
13 |
Correct |
2 ms |
840 KB |
Output is correct |
14 |
Correct |
4 ms |
840 KB |
Output is correct |
15 |
Correct |
3 ms |
844 KB |
Output is correct |
16 |
Correct |
2 ms |
848 KB |
Output is correct |
17 |
Correct |
3 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
968 KB |
Output is correct |
19 |
Correct |
3 ms |
968 KB |
Output is correct |
20 |
Correct |
3 ms |
968 KB |
Output is correct |
21 |
Correct |
3 ms |
968 KB |
Output is correct |
22 |
Correct |
3 ms |
968 KB |
Output is correct |
23 |
Correct |
4 ms |
968 KB |
Output is correct |
24 |
Correct |
4 ms |
968 KB |
Output is correct |
25 |
Correct |
4 ms |
1124 KB |
Output is correct |
26 |
Correct |
4 ms |
1124 KB |
Output is correct |
27 |
Correct |
5 ms |
1124 KB |
Output is correct |
28 |
Correct |
5 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1412 KB |
Output is correct |
2 |
Correct |
6 ms |
1540 KB |
Output is correct |
3 |
Correct |
25 ms |
3084 KB |
Output is correct |
4 |
Correct |
38 ms |
3152 KB |
Output is correct |
5 |
Correct |
16 ms |
3152 KB |
Output is correct |
6 |
Correct |
12 ms |
3152 KB |
Output is correct |
7 |
Correct |
21 ms |
3152 KB |
Output is correct |
8 |
Correct |
22 ms |
3152 KB |
Output is correct |
9 |
Correct |
11 ms |
3152 KB |
Output is correct |
10 |
Correct |
11 ms |
3152 KB |
Output is correct |
11 |
Correct |
27 ms |
3152 KB |
Output is correct |
12 |
Correct |
24 ms |
3152 KB |
Output is correct |
13 |
Correct |
18 ms |
3152 KB |
Output is correct |
14 |
Correct |
20 ms |
3156 KB |
Output is correct |
15 |
Correct |
20 ms |
4056 KB |
Output is correct |
16 |
Correct |
18 ms |
4056 KB |
Output is correct |
17 |
Correct |
26 ms |
4180 KB |
Output is correct |
18 |
Correct |
26 ms |
4188 KB |
Output is correct |
19 |
Correct |
23 ms |
4308 KB |
Output is correct |
20 |
Correct |
23 ms |
4312 KB |
Output is correct |