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"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int n = R;
int ans = 1;
int l = 0;
int r = 0;
int mid = 0;
int cost = 0;
int cntL = 1;
int cntR = 0;
while (l < n) {
while (r+1 < n) {
int prevCost = cost;
int prevMid = mid;
int prevCntL = cntL;
int prevCntR = cntR;
r++;
cntR++;
cost += X[r]-X[mid];
while (cntL < cntR) {
int sz = X[mid+1]-X[mid];
cost += cntL*sz - cntR*sz;
mid++;
cntL++;
cntR--;
}
if (cost > B) {
r--;
cost = prevCost;
mid = prevMid;
cntL = prevCntL;
cntR = prevCntR;
break;
}
}
ans = max(ans, r-l+1);
cost -= X[mid]-X[l];
cntL--;
l++;
}
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... |