#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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
500 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 |
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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
448 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
456 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 |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
3 ms |
832 KB |
Output is correct |
3 |
Correct |
10 ms |
4700 KB |
Output is correct |
4 |
Correct |
10 ms |
4832 KB |
Output is correct |
5 |
Correct |
6 ms |
3420 KB |
Output is correct |
6 |
Correct |
6 ms |
3420 KB |
Output is correct |
7 |
Correct |
12 ms |
4572 KB |
Output is correct |
8 |
Correct |
10 ms |
4444 KB |
Output is correct |
9 |
Correct |
5 ms |
3420 KB |
Output is correct |
10 |
Correct |
6 ms |
3540 KB |
Output is correct |
11 |
Correct |
10 ms |
4700 KB |
Output is correct |
12 |
Correct |
10 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
3480 KB |
Output is correct |
14 |
Correct |
6 ms |
3416 KB |
Output is correct |
15 |
Correct |
8 ms |
4188 KB |
Output is correct |
16 |
Correct |
7 ms |
4132 KB |
Output is correct |
17 |
Correct |
9 ms |
4576 KB |
Output is correct |
18 |
Correct |
11 ms |
4636 KB |
Output is correct |
19 |
Correct |
10 ms |
4788 KB |
Output is correct |
20 |
Correct |
9 ms |
4700 KB |
Output is correct |