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 "ricehub.h"
using namespace std;
typedef long long ll;
int besthub(int R, int L, int X[], long long B)
{
ll pre[R + 1];
int X2[R + 1];
X2[0] = 0;
pre[0] = 0;
for(int i = 1; i <= R; i++){
X2[i] = X[i - 1];
pre[i] = X2[i] + pre[i - 1];
}
int lo = 0; int hi = R;
while(lo < hi){
ll mid = (lo + hi + 1)/2;
bool can = 0;
for(int i = 1; i + mid - 1 <= R; i++){
ll sum = 0;
ll nos = (i + i + mid - 1)/2;
ll k1 = nos - i;
sum += X2[nos]*k1 - (pre[nos - 1] - pre[i - 1]);
ll k2 = (i + mid - 1) - nos;
sum += (pre[i + mid - 1] - pre[nos]) - X2[nos]*k2;
if(sum <= B){
can = 1;
break;
}
}
if(can){
lo = mid;
}
else{
hi = mid - 1;
}
}
return lo;
}
# | 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... |