# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
895790 | 2023-12-30T20:48:13 Z | vjudge1 | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long int ll besthub(ll N, ll L, ll A[], long long B) { vector<ll> p(N + 1); p[0] = 0; for (ll i = 1; i <= N; i++) { p[i] = A[i - 1]; p[i] += p[i - 1]; } ll ans = 0; for (ll i = 1; i <= N; i++) { ll left = i, right = N; while (left <= right) { ll middle = (left + right) / 2; ll median = (i + middle) / 2; ll sum = (p[left + 1] - p[median]) - (left + 1 - median) * A[median - 1] + (median - (i - 1)) * A[median - 1] - (p[median] - p[i - 1]); if (sum <= B) { ans = max(ans, middle - i + 1); left = middle + 1; } else { right = middle - 1; } } } return ans; } // int main() { // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // ll R, L; // cin >> R >> L; // ll X[R]; // for (ll i = 0; i < R; i++) { // cin >> X[i]; // } // ll B; // cin >> B; // cout << besthub(R, L, X, B) << "\n"; // }