Submission #1124170

#TimeUsernameProblemLanguageResultExecution timeMemory
1124170njoopRice Hub (IOI11_ricehub)C++17
100 / 100
12 ms2376 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int n; vector<ll> arr, pre; ll cost(ll k) { ll mnco = 1e18; for(int i=k; i<=n; i++) { ll st = i-k+1, mid = st+(k+1)/2-1; ll left = (arr[mid]*(mid-st+1))-(pre[mid]-pre[st-1]); ll right = (pre[i]-pre[mid])-(arr[mid]*(i-mid)); mnco = min(mnco, left+right); } return mnco; } int besthub(int R, int L, int X[], long long B) { n=R; arr.assign(R+10, 0); pre.assign(R+10, 0); for(int i=1; i<=R; i++) { arr[i] = X[i-1]; pre[i] = pre[i-1] + arr[i]; } ll l=1, r=R+1; while(l < r) { ll mid = (l+r)/2; if(cost(mid) > B) { r = mid; } else { l = 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...