302487: CF479C. Exams

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Exams

题意翻译

## 题目描述 学生进行期末考试,每个考试时间在$a_i$,Valera和老师约定提前于时间$b_i$进行考试,要求所有考试按照$a_i$的顺序,求Valera最早哪个时间可以结束考试。 ### 输入格式 第一行一个整数,考试数目nnn。接下来n+1行每行两个整数代表$a_i$和$b_i$。 ### 输出格式 一个整数,代表最小结束时间。 ##### 数据规模 n<=5000,$a_i$、$b_i$在int范围

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

Input

题意翻译

## 题目描述 学生进行期末考试,每个考试时间在$a_i$,Valera和老师约定提前于时间$b_i$进行考试,要求所有考试按照$a_i$的顺序,求Valera最早哪个时间可以结束考试。 ### 输入格式 第一行一个整数,考试数目nnn。接下来n+1行每行两个整数代表$a_i$和$b_i$。 ### 输出格式 一个整数,代表最小结束时间。 ##### 数据规模 n<=5000,$a_i$、$b_i$在int范围

加入题单

上一题 下一题 算法标签: