#include "ricehub.h"
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int besthub(int R, int L, int X[], long long B) {
vector<ll> ps(R);
ps[0] = X[0];
for (int i = 1; i < R; i++) {
ps[i] = ps[i - 1] + ll(X[i]);
}
int en = 0;
int ans = 0;
for (int st = 0; st < R; st++) {
if (en < st) en = st;
for (; en < R - 1;) {
int mid = (en + 1 - st) / 2 + st;
ll lo = ps[mid] - (st == 0 ? 0 : ps[st - 1]);
ll hi = ps[en + 1] - ps[mid];
ll cost = (mid - st + 1) * ll(X[mid]) - lo + hi -
(en + 1 - mid) * ll(X[mid]);
// cout << "cost " << st << " " << mid << " " << (en + 1) << " "
// << cost << "\n";
// cout << (mid - st + 1) << " " << (en + 1 - mid) << " " << X[mid]
// << "\n";
if (cost <= B)
en++;
else
break;
}
// cout << "ok " << st << " " << en << "\n";
ans = max(ans, en - st + 1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
212 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 |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
316 KB |
Output is correct |
26 |
Correct |
0 ms |
316 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 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 |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
12 ms |
2644 KB |
Output is correct |
4 |
Correct |
12 ms |
2480 KB |
Output is correct |
5 |
Correct |
5 ms |
1236 KB |
Output is correct |
6 |
Correct |
5 ms |
1196 KB |
Output is correct |
7 |
Correct |
10 ms |
2240 KB |
Output is correct |
8 |
Correct |
12 ms |
2124 KB |
Output is correct |
9 |
Correct |
5 ms |
1108 KB |
Output is correct |
10 |
Correct |
5 ms |
1192 KB |
Output is correct |
11 |
Correct |
11 ms |
2516 KB |
Output is correct |
12 |
Correct |
12 ms |
2528 KB |
Output is correct |
13 |
Correct |
7 ms |
1264 KB |
Output is correct |
14 |
Correct |
6 ms |
1292 KB |
Output is correct |
15 |
Correct |
9 ms |
1892 KB |
Output is correct |
16 |
Correct |
8 ms |
1872 KB |
Output is correct |
17 |
Correct |
11 ms |
2228 KB |
Output is correct |
18 |
Correct |
11 ms |
2216 KB |
Output is correct |
19 |
Correct |
10 ms |
2380 KB |
Output is correct |
20 |
Correct |
11 ms |
2348 KB |
Output is correct |