#B3872. Game Show Scheduling

    ID: 11529 Type: Default 1000ms 256MiB

Game Show Scheduling

Game Show Scheduling

Xiao Ming is a contestant in a game show that offers a collection of mini games. The show is divided into nn time segments, and there are nn mini games available. For each mini game ii, if Xiao Ming completes it before the end of time segment TiT_i, he earns a reward of RiR_i. Each mini game requires exactly one time segment to complete, and only one mini game can be played during each segment. The challenge is to determine which mini games to play and in which time segments, so as to maximize the total reward.

More formally, you are given an integer nn and nn pairs (Ti,Ri)(T_i, R_i) where TiT_i is the deadline (time segment by which the game must be completed) and RiR_i is the reward for completing the ii-th mini game. A mini game can only be scheduled in a time segment Ti\le T_i. Find the maximum sum of rewards that can be obtained by scheduling at most one mini game per time segment.

inputFormat

The first line contains an integer nn, representing the number of mini games. Each of the following nn lines contains two space-separated integers: TiT_i and RiR_i, where TiT_i is the deadline time segment by which the ii-th mini game must be completed, and RiR_i is its reward.

outputFormat

Output a single integer representing the maximum total reward that can be obtained by optimally scheduling the mini games.

sample

3
1 10
1 5
3 7
17