#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B) {
long long pref[R];
for (int i = 0; i < R; i++)
pref[i] = (i ? pref[i - 1] : 0) + X[i];
int l = 0, ans = 0;
for (int r = 0; r < R; r++) {
int med = (r - l) / 2 + l;
long long cost = ((long long) X[med]) * (med - l + 1) - (pref[med] - pref[l] + X[l]);
cost += pref[r] - pref[med] - ((long long) X[med]) * (r - med);
if (cost > B) {
l++;
r--;
} else
ans = max(ans, r - l + 1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
3 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
256 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
3 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
256 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
8 ms |
768 KB |
Output is correct |
3 |
Correct |
30 ms |
1700 KB |
Output is correct |
4 |
Correct |
25 ms |
1756 KB |
Output is correct |
5 |
Correct |
9 ms |
1280 KB |
Output is correct |
6 |
Correct |
10 ms |
1280 KB |
Output is correct |
7 |
Correct |
17 ms |
2296 KB |
Output is correct |
8 |
Correct |
14 ms |
2276 KB |
Output is correct |
9 |
Correct |
10 ms |
1152 KB |
Output is correct |
10 |
Correct |
9 ms |
1152 KB |
Output is correct |
11 |
Correct |
24 ms |
2552 KB |
Output is correct |
12 |
Correct |
33 ms |
2552 KB |
Output is correct |
13 |
Correct |
10 ms |
1280 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
15 |
Correct |
23 ms |
2040 KB |
Output is correct |
16 |
Correct |
22 ms |
2040 KB |
Output is correct |
17 |
Correct |
19 ms |
2276 KB |
Output is correct |
18 |
Correct |
19 ms |
2256 KB |
Output is correct |
19 |
Correct |
23 ms |
2404 KB |
Output is correct |
20 |
Correct |
20 ms |
2424 KB |
Output is correct |