#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int besthub(int r, int l, int x[], long long b) {
int ans = 0;
int left = 0, right = 0, middle = 0;
ll leftsum = 0, rightsum = 0;
bool prev = true;
while (right != r - 1) {
if (prev) {
if ((right - left + 1) % 2 == 0) {
right++; middle++;
leftsum += (ll)(middle - left) * (x[middle] - x[middle - 1]);
rightsum -= (ll)(right - middle) * (x[middle] - x[middle - 1]);
rightsum += x[right] - x[middle];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
} else {
right++;
rightsum += x[right] - x[middle];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
}
} else {
if ((right - left + 1) % 2 == 0) {
left++; middle++;
leftsum += (ll)(middle - left + 1) * (x[middle] - x[middle - 1]);
rightsum -= (ll)(right - middle + 1) * (x[middle] - x[middle - 1]);
leftsum -= x[middle] - x[left - 1];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
} else {
left++;
leftsum -= x[middle] - x[left - 1];
if (leftsum + rightsum > b) {
prev = false;
} else {
prev = true;
ans = max(ans, right - left + 1);
}
}
}
//cout << left << ' ' << middle << ' ' << right << ' ' << leftsum << ' ' << rightsum << '\n';
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
352 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
356 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
404 KB |
Output is correct |
21 |
Correct |
1 ms |
356 KB |
Output is correct |
22 |
Correct |
1 ms |
356 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
360 KB |
Output is correct |
26 |
Correct |
1 ms |
360 KB |
Output is correct |
27 |
Correct |
1 ms |
360 KB |
Output is correct |
28 |
Correct |
1 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
360 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
11 ms |
3680 KB |
Output is correct |
4 |
Correct |
10 ms |
3540 KB |
Output is correct |
5 |
Correct |
5 ms |
2924 KB |
Output is correct |
6 |
Correct |
5 ms |
2920 KB |
Output is correct |
7 |
Correct |
7 ms |
3432 KB |
Output is correct |
8 |
Correct |
9 ms |
3312 KB |
Output is correct |
9 |
Correct |
5 ms |
2808 KB |
Output is correct |
10 |
Correct |
4 ms |
2908 KB |
Output is correct |
11 |
Correct |
11 ms |
3684 KB |
Output is correct |
12 |
Correct |
9 ms |
3556 KB |
Output is correct |
13 |
Correct |
4 ms |
2908 KB |
Output is correct |
14 |
Correct |
7 ms |
2908 KB |
Output is correct |
15 |
Correct |
8 ms |
3272 KB |
Output is correct |
16 |
Correct |
7 ms |
3252 KB |
Output is correct |
17 |
Correct |
9 ms |
3416 KB |
Output is correct |
18 |
Correct |
10 ms |
3420 KB |
Output is correct |
19 |
Correct |
9 ms |
3672 KB |
Output is correct |
20 |
Correct |
8 ms |
3560 KB |
Output is correct |