Submission #787564

#TimeUsernameProblemLanguageResultExecution timeMemory
787564baneRice Hub (IOI11_ricehub)C++17
0 / 100
6 ms724 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; } long long avg = pf[r] - pf[l - 1]; if (r - l + 1 == mid){ int itt = upper_bound(X.begin(), X.end(), avg) - X.begin(); for (auto it : {itt,itt-1}){ 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...