#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
//#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int besthub(int R, int L, int X[], long long B){
ll sx=0,dx=R+1;
while(sx<dx-1){
ll m=(sx+dx)/2;
ll tot=0;
ll mi=1e18;
int pos=m/2;
for(int i=0;i<m;i++){
tot+=abs(X[i]-X[pos]);
}
mi=min(mi,tot);
for(int i=m;i<R;i++){
pos++;
tot-=(ll)X[pos-1]-(ll)X[i-m];
tot+=(ll)(m)/2*((ll)X[pos]-X[pos-1]);
tot-=(ll)(m-1)/2*((ll)X[pos]-X[pos-1]);
tot+=(ll)X[i]-X[pos];
mi=min(mi,tot);
}
if(mi<=B)sx=m;
else dx=m;
}
return (int)sx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
21 ms |
1792 KB |
Output is correct |
4 |
Correct |
19 ms |
1792 KB |
Output is correct |
5 |
Correct |
12 ms |
896 KB |
Output is correct |
6 |
Correct |
12 ms |
896 KB |
Output is correct |
7 |
Correct |
18 ms |
1536 KB |
Output is correct |
8 |
Correct |
17 ms |
1536 KB |
Output is correct |
9 |
Correct |
14 ms |
768 KB |
Output is correct |
10 |
Correct |
11 ms |
768 KB |
Output is correct |
11 |
Correct |
22 ms |
1792 KB |
Output is correct |
12 |
Correct |
22 ms |
1792 KB |
Output is correct |
13 |
Correct |
12 ms |
896 KB |
Output is correct |
14 |
Correct |
13 ms |
896 KB |
Output is correct |
15 |
Correct |
18 ms |
1408 KB |
Output is correct |
16 |
Correct |
17 ms |
1408 KB |
Output is correct |
17 |
Correct |
20 ms |
1664 KB |
Output is correct |
18 |
Correct |
21 ms |
1664 KB |
Output is correct |
19 |
Correct |
20 ms |
1664 KB |
Output is correct |
20 |
Correct |
20 ms |
1664 KB |
Output is correct |