This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int 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;
}
if(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(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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |