#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(r < n - 1 && t + a[r + 1] - a[i] <= B) {
++r;
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(t + y2 - x1 > B)
y2 = inf;
if(t + x2 - y1 > B)
x2 = inf;
if(x2 == inf && y2 == inf)
break;
if(y2 <= x1) {
t += y2 - x1;
++r, ++l;
}
else {
t += x2 - y1;
--l, --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;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1072 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1068 ms |
5964 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |