# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60128 | 2018-07-23T17:18:11 Z | streifi | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#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; }