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 n exams.
For the each exam i there are known two days: ai — day of the first opportunity to pass the exam, bi — day of the second opportunity to pass the exam (ai<bi). 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 n 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 n exams, or print -1 if he cannot pass all the exams at all.
波利卡普在贝尔兰国立大学学习。很快他将参加考试,他必须恰好通过 n 门考试。
对于第 i 门考试,已知两个日期:ai —— 首次可参加该考试的日期,bi —— 第二次可参加该考试的日期(满足 ai<bi)。波利卡普每天最多只能参加一门考试。对于每门考试,波利卡普自行决定选择哪一天参加。他必须通过全部 n 门考试。
波利卡普希望尽可能早地通过所有考试。请输出波利卡普能通过全部 n 门考试的最早日期的最小索引;若他根本无法通过全部考试,则输出 -1。
输入格式
The first line of the input contains one integer n (1≤n≤106) — the number of exams.
The next n lines contain two integers each: ai and bi (1≤ai<bi≤109), where ai is the number of day of the first passing the i-th exam and bi is the number of day of the second passing the i-th exam.
输入的第一行包含一个整数 n(1≤n≤106)—— 表示考试的场数。
接下来的 n 行每行包含两个整数:ai 和 bi(1≤ai<bi≤109),其中 ai 表示第 i 场考试第一次通过的日期,bi 表示第 i 场考试第二次通过的日期。
输出格式
If Polycarp cannot pass all the n exams, print -1. Otherwise print the minimum index of day by which Polycarp can do that.
如果波利卡普无法通过全部 n 场考试,则输出 -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测评打分。不知道怎么写?