测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A9287. The Tournament

编程题 普及/提高-

题目描述

The first line contains a pair of integers $n$ and $k$ ( $1<=k<=n+1$ ). The $i$ -th of the following $n$ lines contains two integers separated by a single space — $p_{i}$ and $e_{i}$ ( $0<=p_{i},e_{i}<=200000$ ).

The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.

- In subproblem C1 (4 points), the constraint $1<=n<=15$ will hold.
- In subproblem C2 (4 points), the constraint $1<=n<=100$ will hold.
- In subproblem C3 (8 points), the constraint $1<=n<=200000$ will hold.

输入格式

Print a single number in a single line — the minimum amount of effort Manao needs to use to rank in the top $k$ . If no amount of effort can earn Manao such a rank, output number -1.

输出格式

Consider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters $1$ and $3$ , after which Manao, fighter $2$ , and fighter $3$ will all have 2 points. Manao will rank better than fighter $3$ and worse than fighter $2$ , thus finishing in second place.

Consider the second test case. Even if Manao wins against both opponents, he will still rank third.

输入输出样例

输入 #1
3 2
1 1
1 4
2 2
输出 #1
3
输入 #2
2 1
3 2
4 0
输出 #2
-1
输入 #3
5 2
2 10
2 10
1 1
3 1
3 1
输出 #3
12

说明/提示

Consider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters $1$ and $3$ , after which Manao, fighter $2$ , and fighter $3$ will all have 2 points. Manao will rank better than fighter $3$ and worse than fighter $2$ , thus finishing in second place.

Consider the second test case. Even if Manao wins against both opponents, he will still rank third.
上一题 去做题 下一题