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;
typedef long long ll;
int besthub(int R, int L, int X[], long long B) {
vector<ll> lft;
vector<ll> rgt;
int best = 0;
int n = R;
for (int i = n - 1; i > 0; --i) {
rgt.push_back(X[i]);
}
for (int i = 0; i < n; ++i) {
ll leftm = B;
int cur = 1;
int li = lft.size() - 1;
int ri = rgt.size() - 1;
while (true) {
ll leftd = li >= 0 ? abs(lft[li] - X[i]) : 1e18;
ll rightd = ri >= 0 ? abs(rgt[ri] - X[i]) : 1e18;
if (min(leftd, rightd) > leftm) break;
cur++;
if (leftd < rightd) {
leftm -= leftd;
li--;
} else {
leftm -= rightd;
ri--;
}
}
best = max(best, cur);
lft.push_back(X[i]);
rgt.pop_back();
}
return best;
}
# | 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... |