#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int n; ll arr[N], sum[N], cap;
ll calc(ll i, ll j, ll x) {
ll p = lower_bound(arr,arr+n,x) - arr; p++;
ll ret = x * (p - i) - (sum[p-1] - sum[i-1]);
ret = ret + sum[j] - sum[p-1] - x * (j - p + 1);
return ret;
}
bool can(int k) {
for(int i = k; i <= n; i++) {
ll med = (sum[i] - sum[i-k]) / k;
for(ll m = med-5; m <= med+5; m++)
if(calc(i-k+1,i,m) <= cap) return true;
}
return false;
}
int besthub(int R, int L, int X[], ll B) {
n = R, cap = B; sum[0] = 0;
for(int i = 0; i < R; i++) arr[i] = X[i];
for(int i = 1; i <= R; i++) sum[i] = sum[i-1] + X[i-1];
int lo = 1, hi = R, ret = 0;
while(lo <= hi) {
int mid = (lo + hi) >> 1;
if(can(mid)) ret = mid, lo = mid+1;
else hi = mid-1;
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
560 KB |
Output is correct |
2 |
Correct |
2 ms |
732 KB |
Output is correct |
3 |
Correct |
2 ms |
744 KB |
Output is correct |
4 |
Correct |
2 ms |
748 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
2 ms |
748 KB |
Output is correct |
7 |
Correct |
2 ms |
748 KB |
Output is correct |
8 |
Correct |
2 ms |
748 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
748 KB |
Output is correct |
21 |
Correct |
3 ms |
748 KB |
Output is correct |
22 |
Correct |
3 ms |
748 KB |
Output is correct |
23 |
Correct |
2 ms |
748 KB |
Output is correct |
24 |
Correct |
2 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
748 KB |
Output is correct |
26 |
Correct |
2 ms |
748 KB |
Output is correct |
27 |
Incorrect |
3 ms |
748 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
748 KB |
Output is correct |
2 |
Correct |
2 ms |
748 KB |
Output is correct |
3 |
Correct |
3 ms |
748 KB |
Output is correct |
4 |
Correct |
2 ms |
748 KB |
Output is correct |
5 |
Correct |
3 ms |
748 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
7 |
Correct |
3 ms |
748 KB |
Output is correct |
8 |
Correct |
3 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
3 ms |
748 KB |
Output is correct |
11 |
Correct |
3 ms |
748 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
3 ms |
748 KB |
Output is correct |
16 |
Correct |
3 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
748 KB |
Output is correct |
21 |
Correct |
14 ms |
748 KB |
Output is correct |
22 |
Correct |
11 ms |
748 KB |
Output is correct |
23 |
Correct |
3 ms |
748 KB |
Output is correct |
24 |
Correct |
3 ms |
748 KB |
Output is correct |
25 |
Correct |
3 ms |
748 KB |
Output is correct |
26 |
Correct |
3 ms |
748 KB |
Output is correct |
27 |
Incorrect |
11 ms |
748 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
1020 KB |
Output is correct |
2 |
Correct |
102 ms |
1020 KB |
Output is correct |
3 |
Correct |
17 ms |
2556 KB |
Output is correct |
4 |
Correct |
20 ms |
2556 KB |
Output is correct |
5 |
Correct |
208 ms |
2556 KB |
Output is correct |
6 |
Correct |
207 ms |
2556 KB |
Output is correct |
7 |
Correct |
16 ms |
2556 KB |
Output is correct |
8 |
Correct |
16 ms |
2556 KB |
Output is correct |
9 |
Correct |
183 ms |
2556 KB |
Output is correct |
10 |
Correct |
205 ms |
2556 KB |
Output is correct |
11 |
Correct |
20 ms |
2556 KB |
Output is correct |
12 |
Correct |
20 ms |
2556 KB |
Output is correct |
13 |
Correct |
261 ms |
2556 KB |
Output is correct |
14 |
Correct |
257 ms |
2556 KB |
Output is correct |
15 |
Correct |
15 ms |
3184 KB |
Output is correct |
16 |
Incorrect |
18 ms |
3988 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |