#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 waves of asteroid swarms attacking the Solar System. Each wave has two attributes: , meaning that the -th wave will start on the -th solar day, and the total mass of the swarm is . 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 per solar day. For an asteroid swarm that appears on the -th solar day, if the facility cannot destroy it on day or day (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 , meaning there are waves of asteroid swarms, and at most mass can be destroyed per solar day.
Lines to each contain two non-negative integers , with meanings as described above.
Output Format
Output one line with an integer , 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 of the testdata, .
For of the testdata, .
For of the testdata, .
For another of the testdata, the sum of all is guaranteed to be no more than .
For of the testdata, , .
Translated by ChatGPT 5