CF1027F.Session in BSU

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp studies in Berland State University. Soon he will have to take his exam. He has to pass exactly nn exams.

For the each exam ii there are known two days: aia_i — day of the first opportunity to pass the exam, bib_i — day of the second opportunity to pass the exam (ai<bia_i \lt b_i). Polycarp can pass at most one exam during each day. For each exam Polycarp chooses by himself which day he will pass this exam. He has to pass all the nn exams.

Polycarp wants to pass all the exams as soon as possible. Print the minimum index of day by which Polycarp can pass all the nn exams, or print -1 if he cannot pass all the exams at all.

波利卡普在贝尔兰国立大学学习。很快他将参加考试,他必须恰好通过 nn 门考试。

对于第 ii 门考试,已知两个日期:aia_i —— 首次可参加该考试的日期,bib_i —— 第二次可参加该考试的日期(满足 ai<bia_i \lt b_i)。波利卡普每天最多只能参加一门考试。对于每门考试,波利卡普自行决定选择哪一天参加。他必须通过全部 nn 门考试。

波利卡普希望尽可能早地通过所有考试。请输出波利卡普能通过全部 nn 门考试的最早日期的最小索引;若他根本无法通过全部考试,则输出 -1。

输入格式

The first line of the input contains one integer nn (1≤n≤1061 \le n \le 10^6) — the number of exams.

The next nn lines contain two integers each: aia_i and bib_i (1≤ai<bi≤1091 \le a_i \lt b_i \le 10^9), where aia_i is the number of day of the first passing the ii-th exam and bib_i is the number of day of the second passing the ii-th exam.

输入的第一行包含一个整数 nn(1≤n≤1061 \le n \le 10^6)—— 表示考试的场数。

接下来的 nn 行每行包含两个整数:aia_i 和 bib_i(1≤ai<bi≤1091 \le a_i \lt b_i \le 10^9),其中 aia_i 表示第 ii 场考试第一次通过的日期,bib_i 表示第 ii 场考试第二次通过的日期。

输出格式

If Polycarp cannot pass all the nn exams, print -1. Otherwise print the minimum index of day by which Polycarp can do that.

如果波利卡普无法通过全部 nn 场考试,则输出 -1。否则,输出波利卡普能够做到这一点的最早日期的最小索引。

输入输出样例

  • 输入#1

    2
    1 5
    1 7

    输出#1

    5
  • 输入#2

    3
    5 13
    1 5
    1 7

    输出#2

    7
  • 输入#3

    3
    10 40
    40 80
    10 80

    输出#3

    80
  • 输入#4

    3
    99 100
    99 100
    99 100

    输出#4

    -1

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

首页