LCC '21 Contest 6 J4 - AOE

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

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 N monsters arranged in a line. Each monster has a level L_i, a point value P_i, and is placed at position i. When the player casts their ultimate spell, all monsters with level between some a and b 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 R, 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:

1\le P_i\le 1000

0\le R\le N-1

Subtask 1 [30%]

1\le N\le 1000

1\le L_i\le 1000

Subtask 2 [70%]

1\le N\le 10^5

1\le L_i\le 10^5

Input Specifications

The first line contains N and R, the number of monsters and maximum allowed range of the ultimate spell.

The next N lines contain two integers, L_i and P_i: the level and point value of the i-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 6+9+2=17 points.


Comments

There are no comments at the moment.