Submission #1110450

#TimeUsernameProblemLanguageResultExecution timeMemory
1110450IcelastRice Hub (IOI11_ricehub)C++17
100 / 100
14 ms5372 KiB
#include "ricehub.h" #include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; int besthub(int R, int L, int X[], long long B) { int n = R; vector<ll> a(n+1); for(int i = 1; i <= n; i++){ a[i] = X[i-1]; } vector<ll> pf(n+2, 0); for(int i = 1; i <= n; i++){ pf[i] = pf[i-1]+a[i]; } auto check = [&](int x) -> bool{ for(int i = x; i <= n; i++){ int j = i-x+1; int m = j+(x+1)/2-1; ll left_cost = a[m]*(m-j+1) - (pf[m]-pf[j-1]); ll right_cost = (pf[i]-pf[m]) - a[m]*(i-m); ll cost = left_cost+right_cost; if(cost <= B) return true; } return false; }; int l = 0, r = n, mid; while(l <= r){ 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...