이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |