#include <vector>
#include "ricehub.h"
using namespace std;
vector<long long> s;
long long cost(int st, int dr, int X[]) {
int mid = (st + dr) / 2;
// X[mid + 1] - X[mid] + X[mid + 2] - X[mid]...X[dr] - X[mid];
// X[mid] - X[mid] + X[mid] - X[mid - 1] + ... + X[mid] - X[st]
long long res = s[dr] - s[mid] - s[mid];
if (st != 0) {
res += s[st - 1];
}
if ((dr - st + 1) % 2 == 1) {
res += X[mid];
}
return res;
}
int besthub(int R, int L, int X[], long long B) {
s.assign(R, 0);
for (int i = 0; i < R; i++) {
s[i] += X[i];
if (i != 0) {
s[i] += s[i - 1];
}
}
int st = 0;
int res = 0;
for (int i = 0; i < R; i++) {
while (cost(st, i, X) > B) {
st++;
}
res = max(res, i - st + 1);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
304 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
292 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
296 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
304 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
220 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
232 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
0 ms |
296 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 |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
312 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 |
336 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 |
3 ms |
676 KB |
Output is correct |
2 |
Correct |
3 ms |
624 KB |
Output is correct |
3 |
Correct |
13 ms |
2484 KB |
Output is correct |
4 |
Correct |
13 ms |
2508 KB |
Output is correct |
5 |
Correct |
6 ms |
1180 KB |
Output is correct |
6 |
Correct |
6 ms |
1204 KB |
Output is correct |
7 |
Correct |
11 ms |
2132 KB |
Output is correct |
8 |
Correct |
12 ms |
2240 KB |
Output is correct |
9 |
Correct |
5 ms |
1064 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
13 ms |
2516 KB |
Output is correct |
12 |
Correct |
13 ms |
2476 KB |
Output is correct |
13 |
Correct |
6 ms |
1236 KB |
Output is correct |
14 |
Correct |
6 ms |
1252 KB |
Output is correct |
15 |
Correct |
10 ms |
1948 KB |
Output is correct |
16 |
Correct |
10 ms |
1868 KB |
Output is correct |
17 |
Correct |
12 ms |
2156 KB |
Output is correct |
18 |
Correct |
11 ms |
2208 KB |
Output is correct |
19 |
Correct |
12 ms |
2336 KB |
Output is correct |
20 |
Correct |
13 ms |
2388 KB |
Output is correct |