//#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int* a;
int n,l; long long b, T[2][100010], S[2];
vector<int> vx;
bool f(int x) {
if(x==1)return true;
int i;
long long s1=0, s2=0, c=x/2-(x-x/2);
for(i=0;i<x/2;i++) s1+=vx[a[i]];
for(i=x/2;i<x;i++) s2+=vx[a[i]];
long long r=vx[a[x/2]]*c-s1+s2;
for(i=x;i<n;i++) {
s1-=vx[a[i-x]], s2+=vx[a[i]];
s2-=vx[a[i-x+x/2]], s1+=vx[a[i-x+x/2]];
r=min(r,vx[a[i-x+1+x/2]]*c-s1+s2);
}
return r<=b;
}
int besthub(int R, int L, int X[], long long B)
{
vx.clear();
n=R,l=L,b=B,a=X;
for(int i=0;i<R;i++) vx.push_back(X[i]);
sort(vx.begin(),vx.end());
vx.erase(unique(vx.begin(),vx.end()),vx.end());
for(int i=0;i<R;i++) a[i]=lower_bound(vx.begin(),vx.end(),a[i])-vx.begin();
int lo=0,hi=R;
while(lo<hi){
int mid=(lo+hi+1)/2;
if(f(mid)) lo=mid;
else hi=mid-1;
}
return lo;
}
# |
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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
400 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
400 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
1 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
448 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
632 KB |
Output is correct |
2 |
Correct |
7 ms |
760 KB |
Output is correct |
3 |
Correct |
27 ms |
2400 KB |
Output is correct |
4 |
Correct |
27 ms |
2420 KB |
Output is correct |
5 |
Correct |
13 ms |
1272 KB |
Output is correct |
6 |
Correct |
12 ms |
1272 KB |
Output is correct |
7 |
Correct |
20 ms |
2164 KB |
Output is correct |
8 |
Correct |
21 ms |
2292 KB |
Output is correct |
9 |
Correct |
12 ms |
1144 KB |
Output is correct |
10 |
Correct |
13 ms |
1272 KB |
Output is correct |
11 |
Correct |
29 ms |
2420 KB |
Output is correct |
12 |
Correct |
28 ms |
2424 KB |
Output is correct |
13 |
Correct |
15 ms |
1272 KB |
Output is correct |
14 |
Correct |
15 ms |
1332 KB |
Output is correct |
15 |
Correct |
22 ms |
2036 KB |
Output is correct |
16 |
Correct |
22 ms |
2036 KB |
Output is correct |
17 |
Correct |
26 ms |
2292 KB |
Output is correct |
18 |
Correct |
26 ms |
2292 KB |
Output is correct |
19 |
Correct |
27 ms |
2420 KB |
Output is correct |
20 |
Correct |
27 ms |
2288 KB |
Output is correct |