#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
//but did you try long long?
long long temp_budget = 0;
int len = 1;
int ans = 0;
int l = 0, r = 0;
for(int i = 0; i < R; i ++){
if(r < i){
r = i;
l = i;
len = 1;
temp_budget = 0;
}
while(i - l > r - i){
temp_budget -= X[i] - X[l];
--len;
++l;
}
bool change = true;
while(change){
change = false;
if(i - l < r - i){
if(l > 0 && temp_budget + X[i] - X[l-1] <= B){
temp_budget += X[i] - X[l-1];
++len;
--l;
change = true;
}
}
else if(i - l == r - i){
if(r + 1 < R && temp_budget + X[r+1] - X[i] <= B){
temp_budget += X[r+1] - X[i];
++len;
++r;
change = true;
}
}
}
ans = max(ans, len);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |