#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
} // namespace
int besthub(int R, int L, int X[], long long B)
{
vector<long> pref(R + 1, 0), suff(R + 1, 0);
for (int i = 0; i < R; i++)
pref[i + 1] = pref[i] + X[i];
for (int i = R - 1; i >= 0; i--)
suff[i] = suff[i + 1] - X[i];
cerr << pref[3] << '\n';
int res = 0;
for (int i = 0; i < R; i++)
{
int lo = i, hi = R;
while (lo < hi)
{
int mid = (lo + hi + 1) / 2;
int m = (i + mid) / 2;
// cerr << i << ' ' << mid << ' ' << m << ' ' << pref[mid] - pref[m] << ' ' << suff[i] - suff[m] << ' ' << (long)(mid - i) * X[m] << '\n';
if (pref[mid] - pref[m] + suff[i] - suff[m] - (long)(mid - m) * X[m] - (long)(m - i) * -X[m] <= B)
lo = mid;
else
hi = mid - 1;
}
res = max(res, lo - i);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
308 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
444 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
4 ms |
828 KB |
Output is correct |
3 |
Correct |
18 ms |
3332 KB |
Output is correct |
4 |
Correct |
17 ms |
3284 KB |
Output is correct |
5 |
Correct |
8 ms |
1576 KB |
Output is correct |
6 |
Correct |
7 ms |
1620 KB |
Output is correct |
7 |
Correct |
15 ms |
2972 KB |
Output is correct |
8 |
Correct |
16 ms |
3028 KB |
Output is correct |
9 |
Correct |
7 ms |
1492 KB |
Output is correct |
10 |
Correct |
9 ms |
1492 KB |
Output is correct |
11 |
Correct |
19 ms |
3236 KB |
Output is correct |
12 |
Correct |
16 ms |
3264 KB |
Output is correct |
13 |
Correct |
13 ms |
1620 KB |
Output is correct |
14 |
Correct |
9 ms |
1596 KB |
Output is correct |
15 |
Correct |
13 ms |
2484 KB |
Output is correct |
16 |
Correct |
25 ms |
2548 KB |
Output is correct |
17 |
Correct |
22 ms |
2908 KB |
Output is correct |
18 |
Correct |
14 ms |
2932 KB |
Output is correct |
19 |
Correct |
16 ms |
3156 KB |
Output is correct |
20 |
Correct |
20 ms |
3140 KB |
Output is correct |