Submission #1293730

#TimeUsernameProblemLanguageResultExecution timeMemory
1293730PetyAnts and Sugar (JOI22_sugar)C++20
0 / 100
1 ms572 KiB
#include <bits/stdc++.h> using namespace std; int q, l; deque<pair<long long, long long>>sugar; struct query { long long t, x, a; } Q[3002]; signed main () { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> q >> l; for (int i = 1; i <= q; i++) { cin >> Q[i].t >> Q[i].x >> Q[i].a; } for (int i = 1; i <= q; i++) { for (int j = i - 1; j >= 1; j--) if (Q[j].x > Q[j + 1].x || (Q[j].x == Q[j + 1].x && Q[j].t < Q[j + 1].t)) swap(Q[j], Q[j + 1]); sugar.clear(); long long spate = 0; long long ans = 0; for (int j = 1; j <= i; j++) { if (Q[j].t == 1) { while (sugar.size() && sugar.front().first < Q[j].x - l) sugar.pop_front(); long long x = Q[j].a; while (x && sugar.size()) { ans += min(x, sugar.front().second); x = max(0ll, x - sugar.front().second); sugar.pop_front(); } spate += x; } else { if (spate >= Q[j].a) { spate -= Q[j].a; ans += Q[j].a; } else { sugar.push_back({Q[j].x, Q[j].a - spate}); spate = 0; } } } 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...