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;
#define ll long long
int besthub(int R, int L, int X[], ll B)
{
ll n = R;
ll ans = 1;
ll l = 0;
ll r = 0;
ll mid = 0;
ll cost = 0;
ll cntL = 1;
ll cntR = 0;
while (l < n) {
while (r+1 < n) {
ll prevCost = cost;
ll prevMid = mid;
ll prevCntL = cntL;
ll prevCntR = cntR;
r++;
cntR++;
cost += X[r]-X[mid];
while (cntL < cntR) {
ll 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... |