#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll cum[100005],tab[100005];
ll sum(int a,int b){
if(a>b)return 0;
return cum[b]-(a?cum[a-1]:0);
}
ll cost(int i,int j,int x){
ll idx=lower_bound(tab+i,tab+j+1,x)-tab;
ll nb_a=idx-i,nb_b=j-idx+1;
return nb_a*x-sum(i,idx-1)+sum(idx,j)-nb_b*x;
}
int besthub(int R, int L, int X[], long long B)
{
for (int i = 0; i < R; ++i)
{
tab[i]=X[i];
cum[i]=X[i];
if(i)cum[i]+=cum[i-1];
}
int ans=1;
for (int i = 0; i < R; ++i)
{
for (int j = i+1; j < R; ++j)
{
//cerr<<i<<" "<<j<<" "<<i+(j-i)/2<<"\n";
if(cost(i,j,X[i+(j-i)/2])<=B)
ans=max(ans,j-i+1);
/*
ll x=sum(i,j)/(j-i+1);
if(cost(i,j,x)<=B)ans=max(ans,j-i+1);
else{
x=(sum(i,j)+(j-i))/(j-i+1);
if(cost(i,j,x)<=B)ans=max(ans,j-i+1);
}
*/
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
8 ms |
384 KB |
Output is correct |
4 |
Correct |
8 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
384 KB |
Output is correct |
8 |
Correct |
14 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
10 ms |
384 KB |
Output is correct |
14 |
Correct |
11 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
11 ms |
512 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
411 ms |
492 KB |
Output is correct |
22 |
Correct |
414 ms |
504 KB |
Output is correct |
23 |
Correct |
313 ms |
504 KB |
Output is correct |
24 |
Correct |
312 ms |
512 KB |
Output is correct |
25 |
Correct |
278 ms |
512 KB |
Output is correct |
26 |
Correct |
280 ms |
632 KB |
Output is correct |
27 |
Correct |
286 ms |
632 KB |
Output is correct |
28 |
Correct |
277 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |