CF391C1 The Tournament
题目描述
本题由三个子问题组成:解决子问题 C1 可以获得 4 分,解决子问题 C2 同样可以获得 4 分,而解决子问题 C3 则能获得 8 分。
Manao 决定进军拳击领域,并首次参加了一个正在进行的锦标赛。在他加入前,比赛中已有 $n$ 名选手,编号从 $1$ 到 $n$。每名选手都已获得一定的比赛积分,其中第 $i$ 位选手的积分为 $p_{i}$。
Manao 将与每名选手进行一次比赛。每场比赛的结果要么是胜利,要么是失利。胜利会为 Manao 增加 1 分,而失败则会让对手增加 1 分。对于每一名对手 $i$,Manao 估算了自己需要投入的努力 $e_{i}$ 以击败这名对手。失败不消耗任何努力。
当 Manao 完成全部比赛后,将根据积分决定最终排名,其中 $1$ 排名最高,$n+1$ 为最差。选手将按比赛积分从高到低排名。如果有人与 Manao 的积分相同,那么赢过 Manao 的选手将排在他前面,反之则排在后面。关于其他选手之间相同积分时的排名细节,在此不予考虑。
Manao 的目标是在排名中达到 $k$ 位或更高。请计算他实现这一目标所需投入的最小总努力,如果这个目标无法实现,请输出 -1。
输入格式
第一行输入两个整数 $n$ 和 $k$,($1 \le k \le n+1$)。接下来的 $n$ 行中,第 $i$ 行包含两个由空格分隔的整数 $p_{i}$ 和 $e_{i}$($0 \le p_{i}, e_{i} \le 200000$)。
本题的三个子问题对输入的限制不同,正确地解决子问题会获得不同的分数。以下是子问题的描述:
- 子问题 C1(4 分):满足 $1 \le n \le 15$。
- 子问题 C2(4 分):满足 $1 \le n \le 100$。
- 子问题 C3(8 分):满足 $1 \le n \le 200000$。
输出格式
输出一个整数,表示 Manao 为进入前 $k$ 名所需的最小努力。如果不管怎么努力都无法达到目标,输出 -1。
**本翻译由 AI 自动生成**
说明/提示
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.