CF391C3.The Tournament

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The first line contains a pair of integers nn and kk ( 1<=k<=n+11<=k<=n+1 ). The ii -th of the following nn lines contains two integers separated by a single space — pip_{i} and eie_{i} ( 0<=pi,ei<=2000000<=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<=151<=n<=15 will hold.
  • In subproblem C2 (4 points), the constraint 1<=n<=1001<=n<=100 will hold.
  • In subproblem C3 (8 points), the constraint 1<=n<=2000001<=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 kk . 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 11 and 33 , after which Manao, fighter 22 , and fighter 33 will all have 2 points. Manao will rank better than fighter 33 and worse than fighter 22 , 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 11 and 33 , after which Manao, fighter 22 , and fighter 33 will all have 2 points. Manao will rank better than fighter 33 and worse than fighter 22 , thus finishing in second place.

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

首页