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>
#define ll long long
#include "ricehub.h"
//#include "grader.cpp"
using namespace std;
queue<int> qL, qR;
int besthub(int R, int L, int X[], ll B) {
ll cost = 0, cur = 1;
int ans = 0;
for (int i = 0; i < R; ++i) {
if (i != 0) cost += (X[i]-X[i-1])*qL.size();
if (i != 0) cost -= (X[i]-X[i-1])*qR.size();
if (!qR.empty() && qR.front() == X[i]) qR.pop();
if (cur <= i) cur++;
qL.push(X[i]);
while (cost > B) {
cost -= X[i]-qL.front();
qL.pop();
}
while (cur < R) {
if (cost + X[cur] - X[i] > B) {
if (cost - (X[i]-qL.front()) + (X[cur]-X[i]) <= cost) {
cost -= X[i]-qL.front();
cost += X[cur]-X[i];
qL.pop();
qR.push(X[cur++]);
}
else break;
}
else {
cost += X[cur] - X[i];
qR.push(X[cur++]);
}
}
int cur = qL.size() + qR.size();
ans = max(ans, cur);
}
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... |