#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
long long pre[R];
pre[0] = X[0];
for(int i = 1;i < R;i++){
pre[i] = pre[i-1] + X[i];
}
long long ans = 0;
for(int i = 0;i < R;i++){
int pos = X[i];
long long low = 0;
long long high = R;
while(true){
if(low == high - 1) break;
int s = (low + high) / 2;
int l = i - s;
int u = i + s;
if(l < 0 || u >= R){
high = s;
continue;
}
long long sum = 0ll;
sum += pre[i];
if(l > 0) sum -= pre[l-1];
sum = (s + 1) * pos - sum;
sum += pre[u];
sum -= pre[i];
sum -= pos * s;
if(sum > B){
high = s;
}
else{
low = s;
}
}
ans = max(ans, 2 * low + 1);
int l = i - low;
int u = i + low;
long long sum = 0ll;
sum += pre[i];
if(l > 0) sum -= pre[l-1];
sum = (low + 1) * pos - sum;
sum += pre[u];
sum -= pre[i];
sum -= pos * low;
if(l > 0 && sum + X[l-1] <= B){
ans = max(ans, 2 * low + 2);
}
if(u + 1 < R && sum + X[u+1] <= B){
ans = max(ans, 2 * low + 2);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |