Tabby Cat is making a new RPG! After perfecting the graphics, he has moved on to creating levels and ultimate moves. In this particular level, there are monsters arranged in a line. Each monster has a level , a point value , and is placed at position . When the player casts their ultimate spell, all monsters with level between some and inclusive (chosen by the player) get defeated, and the player gains the sum of the points values of the defeated monsters. However, if the spell must cover a range greater than , then the player will not be able to cast the spell. The range a spell covers is defined as the position of the rightmost monster minus the position of the leftmost monster. Can you figure out the largest number of points the player can get in one cast of the ultimate move?
Constraints
For all subtasks:
Subtask 1 [30%]
Subtask 2 [70%]
Input Specifications
The first line contains and , the number of monsters and maximum allowed range of the ultimate spell.
The next lines contain two integers, and : the level and point value of the -th monster
Output Specifications
Output one integer, the largest number of points the player can gain after casting the ultimate move once.
Sample Input
8 4
4 3
2 5
3 3
4 1
5 6
4 2
5 9
6 2
Sample Output
17
Sample Explanation
It is optimal to take all monsters with level between 5 and 6. This is the fifth, seventh, and eighth monster, which gives us points.
Comments