300811: CF155B. Combination

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Combination

题意翻译

输入一个n表示有n张纸牌,然后输入n行,每行输 入 $a$ 和 $b$ ,表示纸牌的正面和反面,即 这 张牌可以获得 $a$ 分,并且可以玩的牌的数量 +$b$ ,假设顺序不做限制,在剩余纸牌数量 >0 并且剩下可玩的牌数 >0 时,求可以获得的最大分数是多少。

题目描述

Ilya plays a card game by the following rules. A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number $ a_{i} $ , and the bottom contains number $ b_{i} $ , then when the player is playing the card, he gets $ a_{i} $ points and also gets the opportunity to play additional $ b_{i} $ cards. After the playing the card is discarded. More formally: let's say that there is a counter of the cards that can be played. At the beginning of the round the counter equals one. When a card is played, the counter decreases by one for the played card and increases by the number $ b_{i} $ , which is written at the bottom of the card. Then the played card is discarded. If after that the counter is not equal to zero, the player gets the opportunity to play another card from the remaining cards. The round ends when the counter reaches zero or the player runs out of cards. Of course, Ilya wants to get as many points as possible. Can you determine the maximum number of points he can score provided that you know his cards?

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=1000 $ ) — the number of cards Ilya has. Each of the next $ n $ lines contains two non-negative space-separated integers — $ a_{i} $ and $ b_{i} $ ( $ 0<=a_{i},b_{i}<=10^{4} $ ) — the numbers, written at the top and the bottom of the $ i $ -th card correspondingly.

输出格式


Print the single number — the maximum number of points you can score in one round by the described rules.

输入输出样例

输入样例 #1

2
1 0
2 0

输出样例 #1

2

输入样例 #2

3
1 0
2 0
0 2

输出样例 #2

3

说明

In the first sample none of two cards brings extra moves, so you should play the one that will bring more points. In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards.

Input

题意翻译

输入一个n表示有n张纸牌,然后输入n行,每行输 入 $a$ 和 $b$ ,表示纸牌的正面和反面,即 这 张牌可以获得 $a$ 分,并且可以玩的牌的数量 +$b$ ,假设顺序不做限制,在剩余纸牌数量 >0 并且剩下可玩的牌数 >0 时,求可以获得的最大分数是多少。

加入题单

算法标签: