# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861238 | 2023-10-15T17:11:12 Z | sleepntsheep | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
#include <iostream> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> #include "ricehub.h" using namespace std; #define ALL(x) x.begin(), x.end() #define N 100005 using ll = long long; int n, l, z = -1; ll b, p[N], a[N]; int optimal_hub(int l, int r) { return (l+r)/2; } ll sum(int l, int r) { return p[r] - p[l-1]; } ll need_budget(int l, int r, int h) { if (h < l || r < h) return 1e18; return a[h] * (h-l+1) - a[h] * (r-h) + sum(h+1, r) - sum(l, h); } ll need_budget(int l, int r) { return min({need_budget(l, r, optimal_hub(l, r)), need_budget(l, r, optimal_hub(l, r) + 1), need_budget(l, r, optimal_hub(l, r) - 1)}); } ll besthub(int r, int l, int *a, ll b) { for (int i = 1; i <= n; ++i) { p[i] = p[i-1] + a[i]; int l = 1, r = i; while (l <= r) { int y = (l+r)/2; if (need_budget(y, i) <= b) z = max(z, i-y+1), r = y - 1; else l = y + 1; } } return z; }