#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ab(ll x){
return max(x, -x);
}
const int N = (int)1e5 + 9;
ll pref[N];
ll rq(int a, int b){
if(a == 0)
return pref[b];
else
return pref[b] - pref[a - 1];
}
int besthub(int n, int L, int X[], ll B){
int l = 1, r = n + 1;
pref[0] = X[0];
for(int i = 1;i < n;i ++ )
pref[i] += pref[i - 1];
int k;
bool ok;
int med;
ll sum = 0;
while(l + 1 < r){
k = (l + r)/2;
ok = false;
for(int i = 0;i <= n-k;i ++ ){
med = k / 2;
sum = 0;
sum += (1ll * (med + 1) * X[i + med]) - rq(i, med);
sum += rq(med + 1, i + k - 1) - (1ll * (k - med - 1) * X[i + med]);
if(sum <= B)
ok = true;
}
if(ok)
l = k;
else
r = k;
}
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
564 KB |
Output is correct |
2 |
Correct |
2 ms |
564 KB |
Output is correct |
3 |
Correct |
2 ms |
564 KB |
Output is correct |
4 |
Incorrect |
3 ms |
568 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |