CF1879A.Rigged!

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Monocarp organizes a weightlifting competition. There are nn athletes participating in the competition, the ii-th athlete has strength sis_i and endurance eie_i. The 11-st athlete is Monocarp's friend Polycarp, and Monocarp really wants Polycarp to win.

The competition will be conducted as follows. The jury will choose a positive (greater than zero) integer ww, which denotes the weight of the barbell that will be used in the competition. The goal for each athlete is to lift the barbell as many times as possible. The athlete who lifts the barbell the most amount of times will be declared the winner (if there are multiple such athletes — there's no winner).

If the barbell's weight ww is strictly greater than the strength of the ii-th athlete sis_i, then the ii-th athlete will be unable to lift the barbell even one single time. Otherwise, the ii-th athlete will be able to lift the barbell, and the number of times he does it will be equal to his endurance eie_i.

For example, suppose there are 44 athletes with parameters s1=7,e1=4s_1 = 7, e_1 = 4; s2=9,e2=3s_2 = 9, e_2 = 3; s3=4,e3=6s_3 = 4, e_3 = 6; s4=2,e4=2s_4 = 2, e_4 = 2. If the weight of the barbell is 55, then:

  • the first athlete will be able to lift the barbell 44 times;
  • the second athlete will be able to lift the barbell 33 times;
  • the third athlete will be unable to lift the barbell;
  • the fourth athlete will be unable to lift the barbell.

Monocarp wants to choose ww in such a way that Polycarp (the 11-st athlete) wins the competition. Help him to choose the value of ww, or report that it is impossible.

Monocarp 正在组织一场举重比赛。共有 nn 名运动员参加该比赛,其中第 ii 名运动员的力量为 sis_i,耐力为 eie_i。第 11 名运动员是 Monocarp 的朋友 Polycarp,而 Monocarp 非常希望 Polycarp 获胜。

比赛将按如下方式进行:裁判将选定一个正整数 ww(即比赛中所用杠铃的重量)。每名运动员的目标是尽可能多次地举起该杠铃。举起次数最多的运动员将被宣布为冠军(若存在多名运动员并列最多,则无人获胜)。

若杠铃重量 ww 严格大于 第 ii 名运动员的力量 sis_i,则第 ii 名运动员甚至无法举起杠铃一次;否则,第 ii 名运动员可以举起杠铃,且其举起次数等于其耐力 eie_i。

例如,假设有 44 名运动员,参数分别为 s1=7,e1=4s_1 = 7, e_1 = 4;s2=9,e2=3s_2 = 9, e_2 = 3;s3=4,e3=6s_3 = 4, e_3 = 6;s4=2,e4=2s_4 = 2, e_4 = 2。若杠铃重量为 55,则:

  • 第一名运动员可举起杠铃 44 次;
  • 第二名运动员可举起杠铃 33 次;
  • 第三名运动员无法举起杠铃;
  • 第四名运动员无法举起杠铃。

Monocarp 希望选择一个 ww,使得 Polycarp(即第 11 名运动员)赢得比赛。请帮助他确定这样的 ww 的值;若不可能,请报告无法实现。

输入格式

The first line contains one integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case contains one integer nn (2≤n≤1002 \le n \le 100) — the number of athletes. Then nn lines follow, the ii-th of them contains two integers sis_i and eie_i (1≤si≤1091 \le s_i \le 10^9; 1≤ei≤1001 \le e_i \le 100) — the strength and the endurance of the ii-th athlete.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002 \le n \le 100)—— 运动员的数量。随后是 nn 行,其中第 ii 行包含两个整数 sis_i 和 eie_i(1≤si≤1091 \le s_i \le 10^9;1≤ei≤1001 \le e_i \le 100)—— 分别表示第 ii 位运动员的力量和耐力。

输出格式

For each test case, print the answer as follows:

  • if the answer exists, print one integer — the value of ww meeting the constraints. The integer you print should satisfy 1≤w≤1091 \le w \le 10^9. It can be shown that if the answer exists, at least one such value of ww exists as well. If there are multiple answers, you can print any of them;
  • otherwise, print one integer −1-1.

对于每个测试用例,请按如下方式输出答案:

  • 如果答案存在,则输出一个整数——满足约束条件的 ww 的值。您输出的整数应满足 1≤w≤1091 \le w \le 10^9。可以证明:若答案存在,则至少存在一个满足该范围的 ww 值。若存在多个答案,您可以输出其中任意一个;
  • 否则,输出一个整数 −1-1。

输入输出样例

  • 输入#1

    3
    4
    7 4
    9 3
    4 6
    2 2
    2
    4 6
    100 100
    2
    1337 3
    1337 3

    输出#1

    5
    -1
    -1

说明/提示

The first test case of the example is described in the statement.

示例的第一个测试用例已在题目描述中说明。

输入解题思路,AI测评打分。不知道怎么写?

首页