#P8586. 星环防御工事

星环防御工事

Background

An asteroid swarm from outside the Milky Way is about to launch an organized strike on Earth.

Problem Description

According to observations, there will be a total of nn waves of asteroid swarms attacking the Solar System. Each wave has two attributes: di,mid_i, m_i, meaning that the ii-th wave will start on the did_i-th solar day, and the total mass of the swarm is mim_i. Without precise defense, the Solar System may face a catastrophic disaster. Therefore, your boss assigns you the task of building the Starring Defense Facility.

More specifically, the Starring Defense Facility can destroy at most a total asteroid mass of kk per solar day. For an asteroid swarm that appears on the dd-th solar day, if the facility cannot destroy it on day dd or day d+1d+1 (or can only destroy part of it), then the swarm (or its remaining part) will be handed over to the Earth Peace Joint Organization TPC to handle—you certainly do not want someone else to take over your job!

So, you want to know: what is the maximum total asteroid mass that the Starring Defense Facility under your command can destroy?

Input Format

The first line contains two integers n,kn, k, meaning there are nn waves of asteroid swarms, and at most mass kk can be destroyed per solar day.

Lines 22 to n+1n+1 each contain two non-negative integers di,mid_i, m_i, with meanings as described above.

Output Format

Output one line with an integer ansans, representing the maximum total mass of asteroids that can be destroyed.

3 3 
1 6
4 7
2 2
14
10 100
6 14
2 92
3 91
4 74
7 75
2 90
7 25
1 92
3 41
2 14
580

Hint

For 10%10\% of the testdata, 1n,max{di}201\leq n,\max\{d_i\} \leq 20.

For 20%20\% of the testdata, 1n,max{di}6001\leq n,\max\{d_i\}\leq 600.

For 40%40\% of the testdata, 1n,max{di}50001\leq n,\max\{d_i\}\leq 5000.

For another 10%10\% of the testdata, the sum of all mim_i is guaranteed to be no more than kk.

For 100%100\% of the testdata, 1n,max{di}3×1051\leq n,\max\{d_i\}\leq 3\times 10^5, 0mi,k1040\leq m_i,k\leq 10^4.

Translated by ChatGPT 5