# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
418397 | 2021-06-05T10:45:32 Z | temurbek_khujaev | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; int besthub(int R, int L, long long 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; long long d1 = pref[right] - pref[i] - (right - i) * 1ll * X[i]; long long d2 = 1ll * X[i] * (i - left + 1) - pref[i] + (left == 0 ? 0 : pref[left - 1]); good |= d1 + d2 <= B; } left--; right--; if (left >= 0 && right < R) { long long s = 0; long long d1 = pref[right] - pref[i] - (right - i) * 1ll * X[i]; long long d2 = 1ll * X[i] * (i - left + 1) - pref[i] + (left == 0 ? 0 : pref[left - 1]); good |= d1 + d2 <= B; } left+=2; right+=2; if (left >= 0 && right < R) { long long s = 0; long long d1 = pref[right] - pref[i] - (right - i) * 1ll * X[i]; long long d2 = 1ll * X[i] * (i - left + 1) - pref[i] + (left == 0 ? 0 : pref[left - 1]); good |= d1 + d2 <= B; } if (good) { l = m + 1; ans = max(ans, m); } else r = m - 1; } } return ans; }