CF479C.Exams

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.

According to the schedule, a student can take the exam for the i-th subject on the day number a__i. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day b__i (b__i < a__i). Thus, Valera can take an exam for the i-th subject either on day a__i, or on day b__i. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number a__i.

Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.

学生瓦列拉是某大学的一名本科生。期末考试即将来临,他需要恰好通过 nn 门考试。瓦列拉非常聪明,因此他参加的任何一门考试都能在第一次尝试时顺利通过。此外,他可以在同一天内参加多门考试,且考试顺序可以任意安排。

根据教学日程安排,第 ii 门课程的考试可在第 aia_i 天进行。然而,瓦列拉已与每位任课教师达成协议:第 ii 门课程的教师允许他在原定时间之前、即第 bib_i 天(其中 bi<aib_i < a_i)参加考试。因此,瓦列拉可选择在第 bib_i 天或第 aia_i 天参加第 ii 门课程的考试。所有教师均会在实际考试当天将成绩录入瓦列拉的成绩册,并在成绩册中将该成绩的日期登记为原定日期 aia_i。

瓦列拉认为,若成绩册中的各项记录所标注的日期并非非递减顺序,则显得十分奇怪。因此,他请你帮忙解决如下问题:在保证成绩册中所有记录所标注的日期构成一个非递减序列的前提下,瓦列拉完成全部考试所需的最早可能日期是多少?

输入格式

The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take.

Each of the next n lines contains two positive space-separated integers a__i and b__i (1 ≤ b__i < a__i ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.

第一行包含一个正整数 nn(1≤n≤50001 \leq n \leq 5000)—— 表示瓦莱拉将参加的考试场数。

接下来的 nn 行中,每行包含两个以空格分隔的正整数 aia_i 和 bib_i(1≤bi<ai≤1091 \leq b_i < a_i \leq 10^9)—— 分别表示第 ii 场考试在日程表中安排的日期,以及该场考试可提前进行的最早日期。

输出格式

Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.

输出一个整数——瓦莱拉完成所有考试的最早可能的日期编号,要求他参加考试的顺序使得成绩册中所有记录的日期按非递减顺序排列。

输入输出样例

  • 输入#1

    3
    5 2
    3 1
    4 2

    输出#1

    2
  • 输入#2

    3
    6 1
    5 2
    4 3

    输出#2

    6

说明/提示

In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.

In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.

在第一个样例中,瓦莱拉首先在第一天参加第二门科目的考试(教师记录的安排日期为 3)。第二天,他参加第三门科目的考试(教师记录的安排日期为 4),接着参加第一门科目的考试(教师记录的成绩日期为 5)。因此,瓦莱拉最后一天考试是在第二天,而所记录的日期序列为非递减顺序:3、4、5。

在第二个样例中,瓦莱拉首先在第四天参加第三门科目的考试,然后在第五天参加第二门科目的考试,之后在第六天参加第一门科目的考试。

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

首页