Submission #537737

#TimeUsernameProblemLanguageResultExecution timeMemory
537737timreizinRice Hub (IOI11_ricehub)C++17
100 / 100
22 ms2260 KiB
#include "ricehub.h" #include <vector> #include <algorithm> #include <numeric> using namespace std; using ll = long long; int besthub(int n, int , int X[], ll b) { vector<ll> x(n); for (int i = 0; i < n; ++i) x[i] = X[i]; sort(x.begin(), x.end()); vector<ll> pref(n); partial_sum(x.begin(), x.end(), pref.begin()); int maxRes = 0; for (int i = 0; i < n; ++i) { int l = 0, r = n - i; while (l < r) { int m = (l + r) >> 1; int e = i + m; int v = (i + e) >> 1; ll sum = pref[e] - pref[v]; if (v != 0) sum -= pref[v - 1] - (i == 0 ? 0ll : pref[i - 1]); if (i % 2 != e % 2) sum -= x[v]; if (sum <= b) l = m + 1; else r = m; } maxRes = max(maxRes, l); } return maxRes; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...