Submission #787577

#TimeUsernameProblemLanguageResultExecution timeMemory
787577baneRice Hub (IOI11_ricehub)C++17
100 / 100
57 ms3128 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; int besthub(int R, int L, int x[], long long B) { vector<long long>X(R+1); X[0] = -(long long)1e18; for (int i = 1; i <= R; i++){ X[i] = x[i - 1]; } int l = 1, r = R; long long pf[R+1]; pf[0] = 0; for (int i = 1; i<=R; i++){ pf[i] = pf[i - 1] + X[i]; } function<bool(int)>check = [&](int mid){ int r = 0; int l = 1; while(r + 1 <= R){ ++r; while(r - l + 1 > mid){ ++l; } if (r - l + 1 == mid){ int itt = (r + l) / 2; for (int it = itt - 20 ; it <= itt + 20; it++){ if (it < l || it > r)continue; long long sum = 0; if (it != l){ sum += (it - l) * X[it] - (pf[it-1] - pf[l-1]); } if (it != r){ sum += -(r - it) * X[it] + (pf[r] - pf[it]); } if (sum <= B)return true; } } } return false; }; while(l<=r){ int mid = (l+r) / 2; if (check(mid)){ l = mid + 1; }else{ r = mid - 1; } } return l - 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...