#B3872. Game Show Scheduling
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 time segments, and there are mini games available. For each mini game , if Xiao Ming completes it before the end of time segment , he earns a reward of . 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 and pairs where is the deadline (time segment by which the game must be completed) and is the reward for completing the -th mini game. A mini game can only be scheduled in a time segment . 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 , representing the number of mini games. Each of the following lines contains two space-separated integers: and , where is the deadline time segment by which the -th mini game must be completed, and 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