Type: Default 1000ms 256MiB

超市

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

超市里有 $N$ 件商品,每件商品都有利润 $p_i$ 和过期时间 $d_i$,每天只能卖一件商品,过期商品不能再卖。

求合理安排每天卖的商品的情况下,可以得到的最大收益是多少。

Input Format

输入包含多组测试用例。

每组测试用例,以输入整数 $N$ 开始,接下来输入 $N$ 对 $p_i$ 和 $d_i$,分别代表第 $i$ 件商品的利润和过期时间。

在输入中,数据之间可以自由穿插任意个空格或空行,输入至文件结尾时终止输入,保证数据正确。

Output Format

对于每组产品,输出一个该组的最大收益值。

每个结果占一行。

4  
50 2  
10 1   
20 2   
30 1

7  
20 1   
2 1   
10 3  
100 2   
8 2
5 20  
50 10
80
185

Hint

数据范围

$0 \le N \le 10000$,

$1 \le p_i,d_i \le 10000$

最多有 $14$ 组测试样例