http://codeforces.com/contest/479/problem/C

C. 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 < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. 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 ai.

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 < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.

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
3
5 2
3 1
4 2
output
2
input
3
6 1
5 2
4 3
output
6
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门考试的最晚考试时间可最早考试时间,求最后一门考试的最早时间

按最晚时间升序排列,若相同则最早时间升序,贪心即可

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 
 5 struct A{
 6     int s;
 7     int e;
 8 }a[];
 9 
 int cmp(const void *a, const void *b){
     struct A *c = (struct A *)a;
     struct A *d = (struct A *)b;
     if(c->s != d->s)
         return c->s - d->s;
     else return
         c->e - d->e;
 }
 
 int main(){
     int n, i, ans;
     while(scanf("%d", &n) != EOF){
         for(i = ; i < n; i++){
             scanf("%d %d", &a[i].s, &a[i].e);
         }
         qsort(a, n, sizeof(a[]), cmp);
         ans = -;
         for(i = ; i < n; i++){
             if(ans <= a[i].e){
                 ans = a[i].e;
             }
             else{
                 ans = a[i].s;
             }
         }
         printf("%d\n", ans);
     }
     return ;

38 }

Codeforces Round #274 (Div. 2)-C. Exams的更多相关文章

  1. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  2. Codeforces Round #274 (Div. 2) C. Exams (贪心)

    题意:给\(n\)场考试的时间,每场考试可以提前考,但是记录的是原来的考试时间,问你如何安排考试,使得考试的记录时间递增,并且最后一场考试的时间最早. 题解:因为要满足记录的考试时间递增,所以我们用结 ...

  3. Codeforces Round #377 (Div. 2) D. Exams

    Codeforces Round #377 (Div. 2) D. Exams    题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...

  4. Codeforces Round #274 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...

  5. Codeforces Round #377 (Div. 2) D. Exams(二分答案)

    D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...

  6. Codeforces Round #377 (Div. 2) D. Exams 二分

    D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  7. Codeforces Round #274 (Div. 2)

    A http://codeforces.com/contest/479/problem/A 枚举情况 #include<cstdio> #include<algorithm> ...

  8. Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp

    C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...

  9. Codeforces Round #274 (Div. 1) B. Long Jumps 数学

    B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...

随机推荐

  1. 51nod1179【思维】

    题意: 给你n个数,求两两之间的最大GCD: 思路: n太大,然后感觉是分解质因子,但是感觉分解质因子还是搞不出谁和谁的GCD: 但是可以发现,GCD给了一个范围1e6,所以能不能枚举GCD,然后看看 ...

  2. Telnet 对memcached进行数据操作

    连接Telnet 127.0.0.1 11211 存储数据 add news 0 1 8 (news为数据名称,1为存储的时间,当为0的时候则为永久储存,永久缓存最多为30天,8为长度) aaaaaa ...

  3. 3DMAX 3场景制作

    1 模型制作 2 UVW贴图展开 1 打开材质编辑器,给模型一个材质(以后应该以这个材质生成uvw展开,进而生成贴图,贴图绘制完毕后,再贴回这个材质中,就完成了给模型加贴图的操作) 2 在编辑面板中添 ...

  4. django框架知识3

    1.Django安装: 1.安装版本Django1.11.11 2.安装方式:命令行安装   pycharm安装 2.创建Django项目 1.创建方式:cd到你要创建的目录下  然后输入 Djang ...

  5. Java 工程师面试题和笔试题整理(一)

    根据自己之前收集的还有一部分自己面试的整理出来,希望能帮到面试的兄弟(2017). 海科融通 笔试题 1.有一个字符串,如果要在其中查找一个子串,都有哪些方式,写出你认为最好的一个. 2.写出线程都有 ...

  6. [CF1111D] Destory the Colony

    Portal 大致题意: 给定一个偶数长度(\(n \leq 10 ^ 5\))的字符串, 只包含大小写字母. 有q(\(q \leq 10 ^ 5\))次询问, 每次指定两个位置, 要求通过交换字符 ...

  7. HDU6301(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6301 队友AC的,没怎么看 #include<iostream> #incl ...

  8. Codeforces Round #396 (Div. 2) B

    Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 li ...

  9. matplotlib 学习笔记02:marker标记详解

    本文内容来自于matplotlib官网:matplotlib官网markers资料 This module contains functions to handle markers. Used by ...

  10. 模拟IO 读写压力测试

    #### 本实验室通过创建一个测试表myTestTable ,分配在一个足够大小的表空间. ###然后通过 insert select 方式,创建100个后台进程进行读写操作,每个后台进程预计时间20 ...