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 ans = 0;
vector<long long> pref(R, 0);
for (int i = 0; i < R; i++) {
pref[i] = i == 0 ? X[0] : pref[i - 1] + X[i];
}
for (int i = 0; i < R; i++) {
int l = 1, r = R;
while (l <= r) {
int m = (l + r) >> 1;
int left = i - m / 2 + 1;
int right = i + (m + 1) / 2;
bool good = false;
if (left >= 0 && right < R) {
long long s = 0;
assert(right - left + 1 == m);
for (int j = left; j <= right; j++) {
s += abs(X[i] - X[j]);
}
good = s <= B;
// long long d1 = pref[right] - pref[i] - (i + 1) * 1ll * X[i];
// long long d2 = (X[i] - X[left]) * (m / 2) - pref[i] + left == 0 ? 0 : pref[left - 1];
// good = d1 + d2 <= B;
}
if (good) {
l = m + 1;
ans = max(ans, m);
cout << left << ' ' << i << ' ' << right << endl;
} else r = m - 1;
}
}
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... |