#include <bits/stdc++.h>
using namespace std;
#define all(v) begin(v),end(v)
#define pb push_back
using ii = pair<int,int>;
int main() {
int q, l;
cin >> q >> l;
vector<ii> cubev, antv;
while(q--) {
int t, y, x;
cin >> t >> x >> y;
if(t == 1)
cubev.pb({x,y});
else
antv.pb({x,y});
priority_queue<ii,vector<ii>,greater<ii>> cubeq(all(cubev)), antq(all(antv));
int ans = 0;
while(cubeq.size() && antq.size()) {
auto [xant, cant] = antq.top();
auto [xcube, ccube] = cubeq.top();
if(xcube < xant - l) {
cubeq.pop();
continue;
}
if(xant < xcube - l) {
antq.pop();
continue;
}
antq.pop();
cubeq.pop();
if(cant > ccube)
antq.push({xant,cant-ccube});
else if(ccube > cant)
cubeq.push({xcube,ccube-cant});
ans += min(cant, ccube);
}
cout << ans << "\n";
}
}
# | 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... |