#ifndef KienVu
#include "ricehub.h"
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int besthub(int R, int L, int X[], ll B) {
vector<ll> pref(R + 1);
for (int i = 0; i < R; ++i) pref[i + 1] = pref[i] + X[i];
auto cost = [&](int l, int r) {
int md = (l + r) >> 1;
return ll(md + 1 - l) * X[md] - (pref[md + 1] - pref[l]) - ll(r - md) * X[md] + (pref[r + 1] - pref[md + 1]);
};
int ans = 0;
int r = 0;
for (int l = 0; l < R; ++l) {
while (r + 1 < R && cost(l, r + 1) <= B) r++;
ans = max(ans, r - l + 1);
}
return ans;
}
#ifdef KienVu
int main() {
int R, L, B;
while (cin >> R >> L >> B) {
int X[R];
for (int i = 0; i < R; ++i) cin >> X[i];
cout << besthub(R, L, X, B) << "\n";
}
}
#endif // KienVu
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
4 ms |
256 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
256 KB |
Output is correct |
25 |
Correct |
4 ms |
256 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
256 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
640 KB |
Output is correct |
3 |
Correct |
19 ms |
1536 KB |
Output is correct |
4 |
Correct |
20 ms |
1536 KB |
Output is correct |
5 |
Correct |
16 ms |
1280 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
18 ms |
2304 KB |
Output is correct |
8 |
Correct |
18 ms |
2304 KB |
Output is correct |
9 |
Correct |
10 ms |
1280 KB |
Output is correct |
10 |
Correct |
11 ms |
1280 KB |
Output is correct |
11 |
Correct |
21 ms |
2560 KB |
Output is correct |
12 |
Correct |
22 ms |
2560 KB |
Output is correct |
13 |
Correct |
12 ms |
1280 KB |
Output is correct |
14 |
Correct |
12 ms |
1280 KB |
Output is correct |
15 |
Correct |
17 ms |
2048 KB |
Output is correct |
16 |
Correct |
17 ms |
2048 KB |
Output is correct |
17 |
Correct |
21 ms |
2304 KB |
Output is correct |
18 |
Correct |
21 ms |
2312 KB |
Output is correct |
19 |
Correct |
20 ms |
2432 KB |
Output is correct |
20 |
Correct |
23 ms |
2432 KB |
Output is correct |