Submission #978345

#TimeUsernameProblemLanguageResultExecution timeMemory
978345jadai007Rice Hub (IOI11_ricehub)C++17
100 / 100
12 ms4832 KiB
#include "ricehub.h" #include<bits/stdc++.h> using namespace std; using ll = long long; int besthub (int R, int L, int X[], long long B) { vector<int> x(R + 5); vector<ll> pref(R + 5); for (int i = 1; i <= R; i++) x[i] = X[i - 1], pref[i] = pref[i - 1] + x[i]; auto ck = [&] (int val) { for (int l = 1, r = l + val - 1; r <= R; l++, r++) { int mid = (l + r) >> 1; ll curl = x[mid] * (mid - l) - (pref[mid - 1] - pref[l - 1]); ll curr = (pref[r] - pref[mid]) - x[mid] * (r - mid); if (curl + curr <= B) return 1; } return 0; }; int l = 1, r = R; while (l <= r) { int mid = (l + r) >> 1; if (ck(mid)) l = mid + 1; else r = mid - 1; } return r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...