#include "ricehub.h"
#include <iostream>
#include <vector>
#define int long long
using namespace std;
int32_t besthub(int32_t R, int32_t L, int32_t X[], long long B)
{
int n = R;
vector<int> dpSum(n + 1);
for (int i = 1; i <= n; i++) {
dpSum[i] = dpSum[i - 1] + X[i - 1];
}
auto rangeSum = [=](int a, int b) -> int {
return dpSum[b + 1] - dpSum[a];
};
auto cost = [=](int from, int to) -> int {
int median = (from + to) / 2;
int leftN = median - from;
int leftSum = rangeSum(from, median - 1);
int rightN = to - median;
int rightSum = rangeSum(median + 1, to);
int currCost = (X[median] * leftN - leftSum) + (rightSum - X[median] * rightN);
return currCost;
};
int from = 0;
int to = 0;
int res = 1;
while (true) {
to++;
if (to >= n) break;
int currCost = cost(from, to);
if (currCost > B) from++;
else res = max(res, to - from + 1);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
308 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
0 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 |
312 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 |
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 |
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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 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 |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
452 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
13 ms |
4016 KB |
Output is correct |
4 |
Correct |
13 ms |
4104 KB |
Output is correct |
5 |
Correct |
8 ms |
1988 KB |
Output is correct |
6 |
Correct |
6 ms |
2004 KB |
Output is correct |
7 |
Correct |
16 ms |
3800 KB |
Output is correct |
8 |
Correct |
12 ms |
3796 KB |
Output is correct |
9 |
Correct |
6 ms |
1860 KB |
Output is correct |
10 |
Correct |
7 ms |
1876 KB |
Output is correct |
11 |
Correct |
22 ms |
4052 KB |
Output is correct |
12 |
Correct |
14 ms |
4136 KB |
Output is correct |
13 |
Correct |
7 ms |
2012 KB |
Output is correct |
14 |
Correct |
10 ms |
2004 KB |
Output is correct |
15 |
Correct |
13 ms |
3032 KB |
Output is correct |
16 |
Correct |
16 ms |
3156 KB |
Output is correct |
17 |
Correct |
12 ms |
3668 KB |
Output is correct |
18 |
Correct |
23 ms |
3616 KB |
Output is correct |
19 |
Correct |
12 ms |
3812 KB |
Output is correct |
20 |
Correct |
13 ms |
3924 KB |
Output is correct |