# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499931 | 2021-12-30T04:56:34 Z | LittleFlowers__ | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KB |
/* input */ #include<bits/stdc++.h> using namespace std; #include "ricehub.h" typedef long long ll; const int N = 1e5 + 10; int x[N], n; ll pref[N], suff[N], k; ll getR(int l, int r) { return pref[r] - pref[l - 1] - 1LL * (r - l + 1) * (x[l] - x[1]); } ll getL(int l, int r) { return suff[l] - suff[r + 1] - 1LL * (r - l + 1) * (x[n] - x[r]); } bool check(int mid) { --mid; int L = mid / 2, R = (mid + 1) / 2; for (int i = 1; i <= n; ++i) { if (i <= L || i + R > n) continue; ll val = getL(i - L, i) + getR(i, i + R); if(val <= k) return 1; } return 0; } int besthub(int nn,int lll,int xx[],long long bb){ ll l; n=nn,l=lll,k=kk; for (int i = 1; i <= n; ++i) x[i]=xx[i-1]; sort(x + 1, x + n + 1); for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + x[i] - x[1]; for (int i = n; i; --i) suff[i] = suff[i + 1] + x[n] - x[i]; int L = 1, R = n, res = 1; while (L <= R) { int mid = (L + R) / 2; if (check(mid)) { res = mid; L = mid + 1; } else R = mid - 1; } cout << res << "\n"; }