#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 ok(int l, int r) {
ll med = (sum[r] - sum[l-1]) / (r - l + 1);
for(ll i = med - 5; i <= med+5; i++)
if(calc(l,r,i) <= 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 r = 0, ans = 0;
for(int l = 0; l < n; l++) {
while(r + 1 < n && ok(l,r+1)) ++r;
ans = max(ans, r - l + 1);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
472 KB |
Output is correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Correct |
3 ms |
472 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
472 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
612 KB |
Output is correct |
4 |
Correct |
2 ms |
624 KB |
Output is correct |
5 |
Correct |
2 ms |
624 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
644 KB |
Output is correct |
8 |
Correct |
2 ms |
644 KB |
Output is correct |
9 |
Correct |
2 ms |
644 KB |
Output is correct |
10 |
Correct |
0 ms |
644 KB |
Output is correct |
11 |
Correct |
2 ms |
644 KB |
Output is correct |
12 |
Correct |
2 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
780 KB |
Output is correct |
14 |
Correct |
2 ms |
780 KB |
Output is correct |
15 |
Correct |
2 ms |
780 KB |
Output is correct |
16 |
Correct |
2 ms |
780 KB |
Output is correct |
17 |
Incorrect |
2 ms |
780 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
780 KB |
Output is correct |
2 |
Correct |
2 ms |
780 KB |
Output is correct |
3 |
Correct |
2 ms |
844 KB |
Output is correct |
4 |
Correct |
2 ms |
844 KB |
Output is correct |
5 |
Correct |
2 ms |
844 KB |
Output is correct |
6 |
Correct |
2 ms |
844 KB |
Output is correct |
7 |
Correct |
3 ms |
844 KB |
Output is correct |
8 |
Correct |
3 ms |
844 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
844 KB |
Output is correct |
11 |
Correct |
3 ms |
844 KB |
Output is correct |
12 |
Incorrect |
2 ms |
844 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1180 KB |
Output is correct |
2 |
Correct |
17 ms |
1184 KB |
Output is correct |
3 |
Correct |
27 ms |
2716 KB |
Output is correct |
4 |
Correct |
37 ms |
2716 KB |
Output is correct |
5 |
Correct |
61 ms |
2716 KB |
Output is correct |
6 |
Correct |
44 ms |
2716 KB |
Output is correct |
7 |
Correct |
22 ms |
2896 KB |
Output is correct |
8 |
Correct |
26 ms |
2896 KB |
Output is correct |
9 |
Correct |
32 ms |
2896 KB |
Output is correct |
10 |
Correct |
31 ms |
2896 KB |
Output is correct |
11 |
Correct |
29 ms |
2896 KB |
Output is correct |
12 |
Correct |
29 ms |
2896 KB |
Output is correct |
13 |
Correct |
38 ms |
2896 KB |
Output is correct |
14 |
Correct |
42 ms |
2896 KB |
Output is correct |
15 |
Correct |
21 ms |
2896 KB |
Output is correct |
16 |
Incorrect |
23 ms |
2896 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |