#P9528. Ants and Sugar Cubes Experiment
Ants and Sugar Cubes Experiment
Ants and Sugar Cubes Experiment
JOI is a biologist who performs experiments on ants and sugar cubes on a wooden stick of length (10^9). The stick is placed from left to right, and a point at distance (x) from the left end is referred to as the point with coordinate (x).
Initially, the stick is empty. JOI will perform (Q) operations. The (i)-th operation ((1 \le i \le Q)) is described by three integers (T_i, X_i, A_i):
- If \(T_i = 1\), then JOI places \(A_i\) ants at the point with coordinate \(X_i\).
- If \(T_i = 2\), then JOI places \(A_i\) sugar cubes at the point with coordinate \(X_i\).
In this experiment, the ants have a cute trait of being very curious. Specifically, when JOI claps his hands, each ant will perform the following action:
- If there exists at least one sugar cube within a distance \(L\) (i.e. if there is a sugar cube at some coordinate \(y\) such that \(|X_{ant} - y| \le L\)), the ant will choose any one sugar cube and eat it.
- If he claps immediately after the \(k\)-th operation, what is the maximum number of sugar cubes that can be eaten by at least one ant?
Your task is to answer JOI's question for every prefix \(k\) (\(1 \le k \le Q\)).
inputFormat
The first line contains two integers (Q) and (L) ((1 \le Q \le \text{some upper limit},\ 0 \le L \le 10^9)).
Then (Q) lines follow. The (i)-th line contains three space-separated integers (T_i), (X_i), and (A_i). If (T_i = 1), it means an ant is placed at position (X_i); if (T_i = 2), it means sugar cubes are placed at position (X_i).
outputFormat
Output (Q) lines. The (k)-th line should contain the maximum number of sugar cubes that can be eaten by at least one ant, given that all operations from 1 to (k) have been performed and JOI claps his hands.
sample
3 1
1 2 1
2 1 1
2 10 1
0
1
1
</p>