Submission #741769

#TimeUsernameProblemLanguageResultExecution timeMemory
741769Patrick쌀 창고 (IOI11_ricehub)C++17
100 / 100
12 ms2644 KiB
#include "ricehub.h" #include <iostream> #include <vector> using namespace std; using ll = long long; int besthub(int R, int L, int X[], long long B) { vector<ll> ps(R); ps[0] = X[0]; for (int i = 1; i < R; i++) { ps[i] = ps[i - 1] + ll(X[i]); } int en = 0; int ans = 0; for (int st = 0; st < R; st++) { if (en < st) en = st; for (; en < R - 1;) { int mid = (en + 1 - st) / 2 + st; ll lo = ps[mid] - (st == 0 ? 0 : ps[st - 1]); ll hi = ps[en + 1] - ps[mid]; ll cost = (mid - st + 1) * ll(X[mid]) - lo + hi - (en + 1 - mid) * ll(X[mid]); // cout << "cost " << st << " " << mid << " " << (en + 1) << " " // << cost << "\n"; // cout << (mid - st + 1) << " " << (en + 1 - mid) << " " << X[mid] // << "\n"; if (cost <= B) en++; else break; } // cout << "ok " << st << " " << en << "\n"; ans = max(ans, en - st + 1); } 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...