Submission #704569

#TimeUsernameProblemLanguageResultExecution timeMemory
704569tonowakAnts and Sugar (JOI22_sugar)C++17
6 / 100
4066 ms2412 KiB
#include "bits/stdc++.h" // Tomasz Nowak using namespace std; // University of Warsaw using LL = long long; #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) #define ssize(x) int(x.size()) template<class A, class B> auto& operator<<(ostream &o, pair<A, B> p) { return o << '(' << p.first << ", " << p.second << ')'; } template<class T> auto operator<<(ostream &o, T x) -> decltype(x.end(), o) { o << '{'; int i = 0; for(auto e : x) o << (", ")+2*!i++ << e; return o << '}'; } #ifdef DEBUG #define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' #else #define debug(...) {} #endif LL get_ans(map<int, LL> ants, map<int, LL> sugars, int l) { LL ret = 0; while(not ants.empty() and not sugars.empty()) { auto [x, cnt] = *ants.begin(); if(cnt == 0) ants.erase(ants.begin()); else { auto [x_s, cnt_s] = *sugars.begin(); if(cnt_s == 0 or x_s < x - l) sugars.erase(sugars.begin()); else if(x < x_s - l) ants.erase(ants.begin()); else { LL taking = min(cnt, cnt_s); ants.begin()->second -= taking; sugars.begin()->second -= taking; ret += taking; } } } return ret; } int main() { cin.tie(0)->sync_with_stdio(0); int q, l; cin >> q >> l; map<int, LL> ants, sugars; while(q --> 0) { int ti, xi, ai; cin >> ti >> xi >> ai; (ti == 1 ? ants : sugars)[xi] += ai; cout << get_ans(ants, sugars, l) << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...