#include <bits/stdc++.h>
using namespace std;
long long const inf=1e16;
int const N=1e5+5;
long long pre[N];
int cor[N];
long long bug=0;
bool cost(int l,int r){
// cout<<l<<' '<<r<<" checking for it"<<endl;
int p=(l+r)/2;
// cout<<p<<" hub"<<endl;
long long c=0;
int s1=p-l;
int s2=(r+1)-p;
long long sm1=(cor[p]*s1)-(pre[p]-pre[l]);
long long sm2=(pre[r+1]-pre[p])-(cor[p]*s2);
c=sm1+sm2;
// cout<<c<<endl;
return (c<=bug);
}
int besthub(int R, int L, int X[], long long B){
bug=B;
for (int i = 0; i < R; ++i){
pre[i+1]=pre[i]+X[i];
cor[i]=X[i];
}
int low=1,high=R+1;
while(high-low>1){
int mid=(high+low)/2;
// cout<<mid<<' '<<" mid"<<endl;
bool b=0;
for (int i = 0; (i+mid)-1 < R; ++i)
b|=cost(i,(i+mid)-1);
if(b)
low=mid;
else
high=mid;
}
return low;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2496 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2492 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2492 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2504 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2460 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2508 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2540 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2608 KB |
Output is correct |
2 |
Correct |
3 ms |
2652 KB |
Output is correct |
3 |
Correct |
10 ms |
3676 KB |
Output is correct |
4 |
Correct |
9 ms |
3676 KB |
Output is correct |
5 |
Correct |
6 ms |
2836 KB |
Output is correct |
6 |
Correct |
6 ms |
2908 KB |
Output is correct |
7 |
Correct |
8 ms |
3268 KB |
Output is correct |
8 |
Correct |
8 ms |
3420 KB |
Output is correct |
9 |
Correct |
9 ms |
2736 KB |
Output is correct |
10 |
Correct |
5 ms |
2908 KB |
Output is correct |
11 |
Correct |
9 ms |
3672 KB |
Output is correct |
12 |
Correct |
9 ms |
3672 KB |
Output is correct |
13 |
Correct |
6 ms |
2904 KB |
Output is correct |
14 |
Correct |
6 ms |
2908 KB |
Output is correct |
15 |
Correct |
7 ms |
3248 KB |
Output is correct |
16 |
Correct |
7 ms |
3420 KB |
Output is correct |
17 |
Correct |
9 ms |
3672 KB |
Output is correct |
18 |
Correct |
8 ms |
3420 KB |
Output is correct |
19 |
Correct |
10 ms |
3676 KB |
Output is correct |
20 |
Correct |
8 ms |
3676 KB |
Output is correct |