Submission #781198

#TimeUsernameProblemLanguageResultExecution timeMemory
781198zsomborRice Hub (IOI11_ricehub)C++17
100 / 100
26 ms3352 KiB
#include <iostream> #include <vector> #include "ricehub.h" using namespace std; using ll = long long; int n, ans; ll m; vector <ll> r(1e5 + 1, 0); vector <ll> p(1e5 + 1, 0); ll sum(int L, int R) { return p[R] - p[L - 1]; } ll distL(int i, int cnt) { int L = i - cnt < 1 ? 1 : i - cnt; return r[i] * (i - L) - sum(L, i - 1); } ll distR(int i, int cnt) { int R = i + cnt > n ? n : i + cnt; return sum(i + 1, R) - r[i] * (R - i); } ll dist(int i, int cnt) { return distL(i, cnt) + distR(i, cnt); } void solve(int i) { int a = 0, b = n, c; while (b - a > 1) { c = (a + b) / 2; dist(i, c) <= m ? a = c : b = c; } int L = max(1, i - a), R = min(n, i + a); ans = max(ans, R - L + 1); if (L > 1 && dist(i, a) + r[i] - r[L - 1] < m) ans = max(ans, R - L + 2); if (R < n && dist(i, a) + r[R + 1] - r[i] < m) ans = max(ans, R - L + 2); } int besthub(int N, int L, int R[], ll M) { n = N; m = M; for (int i = 1; i <= n; i++) { r[i] = R[i - 1]; p[i] = p[i - 1] + r[i]; } for (int i = 1; i <= n; i++) solve(i); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...