当前位置:Gxlcms > html代码 > CodeforcesRound#274(Div.2)CExams_html/css_WEB-ITnose

CodeforcesRound#274(Div.2)CExams_html/css_WEB-ITnose

时间:2021-07-01 10:21:17 帮助过:22人阅读

题目链接:Exams



Exams

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ai. 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 bi (bi?

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.

Input

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 ai and bi (1?≤?bi?

Output

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.

Sample test(s)

input

35 23 14 2

output

input

36 15 24 3

output

Note

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.




大致题意:一个学生,要参加n场考试,但是他想尽快的把所有考试都考完。对于第 i 场考试,老师规定的时间是ai, 他自己安排的时间是bi ,且ai > bi 。现在有一个原则,你的考试时间顺序不能和老师安排的每场考试时间的先后顺序不一致,且这个学生可以在同一时间完成无穷多的考试。问他完成全部考试的最早时间是多少。



解题思路:我最先想到的就是贪心。CF给出的分类是dp,我感觉还是更像贪心。可能没看出来吧,那就先讲讲怎么贪心吧。先按老师给的时间升序给所有考试排序,当时间相等时,按学生给出的时间升序排序。用ans纪录上一次考试结束时间,然后每次都取ai和bi里面最小的bi,如果bi >= ans, ans = bi;否则,ans = ai,然后继续下一次比较。 最后输出ans即可。




AC代码:

#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define INF 0x7ffffffftypedef struct{    long long x, y;}T;T t[5005];bool cmp(T a, T b){    if(a.x == b.x) return a.y < b.y;    return a.x < b.x;}int main(){    #ifdef sxk        freopen("in.txt","r",stdin);    #endif    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=0; i

人气教程排行