#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int besthub (int R, int L, int X[], long long B) {
vector<int> x(R + 5);
vector<ll> pref(R + 5);
for (int i = 1; i <= R; i++) x[i] = X[i - 1], pref[i] = pref[i - 1] + x[i];
auto ck = [&] (int val) {
for (int l = 1, r = l + val - 1; r <= R; l++, r++) {
int mid = (l + r) >> 1;
ll curl = x[mid] * (mid - l) - (pref[mid - 1] - pref[l - 1]);
ll curr = (pref[r] - pref[mid]) - x[mid] * (r - mid);
if (curl + curr <= B) return 1;
}
return 0;
};
int l = 1, r = R;
while (l <= r) {
int mid = (l + r) >> 1;
if (ck(mid)) l = mid + 1;
else r = mid - 1;
}
return r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
420 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
3700 KB |
Output is correct |
4 |
Correct |
10 ms |
3692 KB |
Output is correct |
5 |
Correct |
6 ms |
3164 KB |
Output is correct |
6 |
Correct |
6 ms |
3420 KB |
Output is correct |
7 |
Correct |
9 ms |
4696 KB |
Output is correct |
8 |
Correct |
9 ms |
4444 KB |
Output is correct |
9 |
Correct |
5 ms |
3308 KB |
Output is correct |
10 |
Correct |
6 ms |
3420 KB |
Output is correct |
11 |
Correct |
10 ms |
4756 KB |
Output is correct |
12 |
Correct |
10 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
3416 KB |
Output is correct |
14 |
Correct |
6 ms |
3420 KB |
Output is correct |
15 |
Correct |
7 ms |
4188 KB |
Output is correct |
16 |
Correct |
8 ms |
4196 KB |
Output is correct |
17 |
Correct |
11 ms |
4444 KB |
Output is correct |
18 |
Correct |
9 ms |
4440 KB |
Output is correct |
19 |
Correct |
10 ms |
4696 KB |
Output is correct |
20 |
Correct |
9 ms |
4696 KB |
Output is correct |