Submission #514180

#TimeUsernameProblemLanguageResultExecution timeMemory
514180ElegiaThe short shank; Redemption (BOI21_prison)C++17
100 / 100
238 ms47916 KiB
#include <cmath> #include <algorithm> #include <stack> #include <bitset> #include <numeric> #include <iostream> #include <vector> #include <string> #include <set> #include <queue> #include <map> #include <unordered_map> using namespace std; const int _ = 2000010; int ans; int t[_], l[_], r[_], cnt[_], mx[_]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N, D, T; cin >> N >> D >> T; for (int i = 1; i <= N; ++i) cin >> t[i]; stack<int> stk; for (int i = N; i; --i) { if (t[i] > T) continue; ++ans; int lst = l[ans] = i; r[ans] = min(N, i + T - t[i]); while (true) { if (!stk.empty() && r[ans] >= r[stk.top()]) { int p = stk.top(); stk.pop(); --cnt[mx[ans]]; ++cnt[mx[ans] += l[p] - lst - 1]; mx[ans] = max(mx[ans], mx[p]); lst = r[p]; } else { if (!stk.empty()) r[ans] = min(l[stk.top()] - 1, r[ans]); --cnt[mx[ans]]; ++cnt[mx[ans] += r[ans] - lst]; break; } } stk.push(ans); } for (int i = N; i; --i) { int v = min(D, cnt[i]); D -= v; cnt[i] -= v; } for (int i = 1; i <= N; ++i) ans += cnt[i] * i; cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...