제출 #799609

#제출 시각아이디문제언어결과실행 시간메모리
799609eltu0815Ants and Sugar (JOI22_sugar)C++14
6 / 100
4045 ms2572 KiB
#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define inf (1000000001)
 
using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
int q, l;
map<int, ll> mp1, mp2;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> q >> l;
    while(q--) {
        int t, a, b; cin >> t >> a >> b;
        if(t == 1) mp1[a] += b;
        else mp2[a] += b;
        
        ll ans = 0;
        auto ant = mp1, sugar = mp2;
        for(auto it = ant.begin(); it != ant.end(); ++it) {
            while(!sugar.empty() && (*it).second) {
                if((*sugar.begin()).first - (*it).first > l) break;
                else if(abs((*sugar.begin()).first - (*it).first) > l) sugar.erase(sugar.begin());
                else if((*sugar.begin()).second <= (*it).second) {
                    ans += (*sugar.begin()).second;
                    (*it).second -= (*sugar.begin()).second;
                    sugar.erase(sugar.begin());
                }
                else {
                    ans += (*it).second;
                    (*sugar.begin()).second -= (*it).second;
                    (*it).second = 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...