#include <bits/stdc++.h>
#include "ricehub.h"
#define f first
#define s second
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int n = R;
int a[n];
for(int i = 0;i < n;i++)
a[i] = X[i];
int ans = 1;
int l = 0, r = 0;
const int inf = 1e9 + 69;
long long t = 0;
while(r < n - 1 && t + a[r + 1] - a[0] <= B) {
++r;
t += (a[r] - a[0]);
++ans;
}
for(int i = 1;i < n;i++) {
if(i > r) {
l = r = i;
t = 0;
while(r < n - 1 && t + a[r + 1] - a[i] <= B) {
++r;
t += (a[r] - a[i]);
}
}
else {
t -= (r - i + 1) * (a[i] - a[i - 1]);
t += (i - l) * (a[i] - a[i - 1]);
while(t > B) {
if(a[i] - a[l] >= a[r] - a[i])
t -= (a[i] - a[l++]);
else
t -= (a[r--] - a[i]);
}
while(t <= B) {
int x1 = inf, x2 = inf, y1 = inf, y2 = inf;
x1 = a[i] - a[l];
y1 = a[r] - a[i];
if(l > 0)
x2 = a[i] - a[l - 1];
if(r < n - 1)
y2 = a[r + 1] - a[i];
if(x2 == inf && y2 == inf)
break;
if(y2 <= x1) {
t += y2 - x1;
++r, ++l;
}
else if(x2 < y1) {
t += x2 - y1;
--l, --r;
}
else
break;
}
while(t <= B) {
int x = inf, y = inf;
if(l > 0)
x = a[i] - a[l - 1];
if(r < n - 1)
y = a[r + 1] - a[i];
if(t + x > B)
x = inf;
if(t + y > B)
y = inf;
if(x == inf && y == inf)
break;
if(x <= y)
t += x, --l;
else
t += y, ++r;
}
}
ans = max(ans, r - l + 1);
}
return ans;
}
// signed main()
// {
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// int tt = 1;
// //cin >> tt;
// while(tt--) {
// int n, k;
// long long x;
// cin >> n >> k >> x;
// int a[n];
// for(int i = 0;i < n;i++)
// cin >> a[i];
// cout << besthub(n, k, a, x);
// }
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
308 KB |
Output is correct |
14 |
Correct |
0 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
312 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
312 KB |
Output is correct |
22 |
Correct |
0 ms |
312 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 |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
312 KB |
Output is correct |
11 |
Correct |
0 ms |
312 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
0 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 |
320 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 |
320 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
356 KB |
Output is correct |
27 |
Correct |
1 ms |
348 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 |
584 KB |
Output is correct |
3 |
Correct |
12 ms |
1176 KB |
Output is correct |
4 |
Correct |
10 ms |
1216 KB |
Output is correct |
5 |
Correct |
5 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
712 KB |
Output is correct |
7 |
Correct |
10 ms |
1184 KB |
Output is correct |
8 |
Correct |
9 ms |
1100 KB |
Output is correct |
9 |
Correct |
4 ms |
728 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
10 ms |
1188 KB |
Output is correct |
12 |
Incorrect |
10 ms |
1164 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |