Submission #958094

#TimeUsernameProblemLanguageResultExecution timeMemory
958094d4xnRice Hub (IOI11_ricehub)C++17
68 / 100
12 ms3680 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; int besthub(int R, int L, int X[], long long B) { int n = R; int ans = 1; int l = 0; int r = 0; int mid = 0; int cost = 0; int cntL = 1; int cntR = 0; while (l < n) { while (r+1 < n) { int prevCost = cost; int prevMid = mid; int prevCntL = cntL; int prevCntR = cntR; r++; cntR++; cost += X[r]-X[mid]; while (cntL < cntR) { int sz = X[mid+1]-X[mid]; cost += cntL*sz - cntR*sz; mid++; cntL++; cntR--; } if (cost > B) { r--; cost = prevCost; mid = prevMid; cntL = prevCntL; cntR = prevCntR; break; } } ans = max(ans, r-l+1); cost -= X[mid]-X[l]; cntL--; l++; } 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...