#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
using ll = long long;
const int N = 100010;
ll qsl[N], qsr[N];
int besthub(int n, int L, int pos[], ll budget)
{
for (int i = 1; i <= n; ++i) {
qsl[i] += qsl[i-1] + pos[i-1];
qsr[i] = qsr[i-1] + (L - pos[i-1]);
}
auto check = [&] (int cnt) {
for (int l = 1, r = cnt; r <= n; ++l, ++r) {
int m = (l+r)/2;
ll d = qsr[m]-qsr[l-1] - (L-pos[m-1])*(m-l+1);
d += qsl[r]-qsl[m] - (pos[m-1])*(r-m);
if (d <= budget) return true;
}
return false;
};
int b = 0;
int e = n;
while (b < e) {
int m = (b+e+1)/2;
if (check(m))
b = m;
else
e = m-1;
}
return b;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
628 KB |
Output is correct |
3 |
Correct |
2 ms |
628 KB |
Output is correct |
4 |
Correct |
2 ms |
628 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
868 KB |
Output is correct |
2 |
Correct |
2 ms |
908 KB |
Output is correct |
3 |
Correct |
2 ms |
1000 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
3 ms |
1028 KB |
Output is correct |
6 |
Correct |
2 ms |
1028 KB |
Output is correct |
7 |
Correct |
3 ms |
1032 KB |
Output is correct |
8 |
Correct |
3 ms |
1036 KB |
Output is correct |
9 |
Correct |
2 ms |
1040 KB |
Output is correct |
10 |
Correct |
3 ms |
1040 KB |
Output is correct |
11 |
Correct |
2 ms |
1152 KB |
Output is correct |
12 |
Correct |
3 ms |
1152 KB |
Output is correct |
13 |
Correct |
2 ms |
1152 KB |
Output is correct |
14 |
Correct |
2 ms |
1152 KB |
Output is correct |
15 |
Correct |
3 ms |
1184 KB |
Output is correct |
16 |
Correct |
3 ms |
1184 KB |
Output is correct |
17 |
Correct |
3 ms |
1184 KB |
Output is correct |
18 |
Correct |
3 ms |
1184 KB |
Output is correct |
19 |
Correct |
3 ms |
1184 KB |
Output is correct |
20 |
Correct |
2 ms |
1184 KB |
Output is correct |
21 |
Correct |
2 ms |
1184 KB |
Output is correct |
22 |
Correct |
3 ms |
1184 KB |
Output is correct |
23 |
Correct |
2 ms |
1204 KB |
Output is correct |
24 |
Correct |
2 ms |
1204 KB |
Output is correct |
25 |
Correct |
2 ms |
1216 KB |
Output is correct |
26 |
Correct |
2 ms |
1216 KB |
Output is correct |
27 |
Correct |
3 ms |
1216 KB |
Output is correct |
28 |
Correct |
2 ms |
1216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1216 KB |
Output is correct |
2 |
Correct |
2 ms |
1244 KB |
Output is correct |
3 |
Correct |
2 ms |
1244 KB |
Output is correct |
4 |
Correct |
3 ms |
1244 KB |
Output is correct |
5 |
Correct |
4 ms |
1244 KB |
Output is correct |
6 |
Correct |
3 ms |
1244 KB |
Output is correct |
7 |
Correct |
2 ms |
1260 KB |
Output is correct |
8 |
Correct |
3 ms |
1260 KB |
Output is correct |
9 |
Correct |
3 ms |
1260 KB |
Output is correct |
10 |
Correct |
3 ms |
1328 KB |
Output is correct |
11 |
Correct |
3 ms |
1328 KB |
Output is correct |
12 |
Correct |
2 ms |
1328 KB |
Output is correct |
13 |
Correct |
2 ms |
1340 KB |
Output is correct |
14 |
Correct |
3 ms |
1352 KB |
Output is correct |
15 |
Correct |
2 ms |
1352 KB |
Output is correct |
16 |
Correct |
3 ms |
1352 KB |
Output is correct |
17 |
Correct |
2 ms |
1352 KB |
Output is correct |
18 |
Correct |
2 ms |
1352 KB |
Output is correct |
19 |
Correct |
3 ms |
1352 KB |
Output is correct |
20 |
Correct |
4 ms |
1352 KB |
Output is correct |
21 |
Correct |
4 ms |
1352 KB |
Output is correct |
22 |
Correct |
4 ms |
1352 KB |
Output is correct |
23 |
Correct |
5 ms |
1368 KB |
Output is correct |
24 |
Correct |
4 ms |
1524 KB |
Output is correct |
25 |
Correct |
4 ms |
1556 KB |
Output is correct |
26 |
Correct |
5 ms |
1596 KB |
Output is correct |
27 |
Correct |
4 ms |
1636 KB |
Output is correct |
28 |
Correct |
4 ms |
1676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2104 KB |
Output is correct |
2 |
Correct |
6 ms |
2236 KB |
Output is correct |
3 |
Correct |
18 ms |
4812 KB |
Output is correct |
4 |
Incorrect |
27 ms |
5872 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |