# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60128 | streifi | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KiB |
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 <iostream>
#include <vector>
using namespace std;
#define int long long
int R, L, B;
vector<int> lft, rght;
vector<int> v;
bool check(int sz) {
for (int l = 0; l+sz-1 < R; ++l) {
int r = l+sz-1;
int med = (l+r)/2;
//cout << l << " " << med << " " << r << endl;
//cout << lft[r+1]-lft[med+1] << " " << rght[l+1]-rght[med+1] << endl;
int cur = lft[r+1]-lft[med+1]-(r-med)*v[med] + rght[l+1]-rght[med+1]-(med-l)*(L-v[med]);
//cout << cur << endl;
if (cur <= B)
return true;
}
return false;
}
signed main() {
cin >> R >> L >> B;
lft.resize(R+2, 0);
rght.resize(R+2, 0);
v.resize(R);
for (int i = 0; i < R; ++i) {
cin >> v[i];
}
for (int i = 1; i <= R; ++i) {
lft[i] = lft[i-1]+v[i-1];
}
for (int i = R; i >= 1; --i) {
rght[i] = rght[i+1]+(L-v[i-1]);
}
int ans = 0;
for (int msk = (1 << 20); msk > 0; msk >>= 1) {
if ((ans | msk) <= R && check(ans | msk)) {
ans |= msk;
}
}
cout << ans << endl;
}