Submission #791102

#TimeUsernameProblemLanguageResultExecution timeMemory
791102max0000561Ants and Sugar (JOI22_sugar)C++17
6 / 100
4075 ms1732 KiB
#include<bits/stdc++.h> #define int long long #define sz(a) (int)a.size() using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int q, L; cin >> q >> L; int Q = 0; vector<pair<int, int>> m, s; while (q--) { ++Q; int t, x, a; cin >> t >> x >> a; if (t == 1) { m.push_back({x, a}); } else { s.push_back({x, a}); } vector<pair<int, int>> M = m, S = s; sort(M.begin(), M.end()); sort(S.begin(), S.end()); int r = 0, ans = 0; for (int i = 0; i < sz(M); ++i) { while (r < sz(S) && M[i].first - S[r].first > L) { ++r; } if (r == sz(S)) break; while (r < sz(S) && abs(S[r].first - M[i].first) <= L) { if (M[i].second > S[r].second) { ans += S[r].second; M[i].second -= S[r].second; S[r].second = 0; ++r; } else { ans += M[i].second; S[r].second -= M[i].second; M[i].second = 0; break; } } } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...