A. Exams

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/480/problem/A

Description

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 Input

3
5 2
3 1
4 2

Sample Output

2

HINT

题意

在期末,有一个人准备完成n(n<=5000)门考试,每门考试你可以选择在第ai天考试,也可以在第bi天考试。

但是不管怎么样,最后你所考试的顺序的a[i],一定是非降的

问你,最少第几天能够考完所有试

题解:

贪心就好了,第一维排序,然后第二位排序

然后贪心选最小就行了

代码:

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std; pair<int,int> a[]; int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&a[i].first,&a[i].second);
sort(a+,a+n+);
int ans = a[].second;
for(int i=;i<=n;i++)
{
if(a[i].second >= ans)
ans = min(a[i].second,a[i].first);
else
ans = a[i].first;
}
printf("%d\n",ans);
}

Codeforces Round #274 (Div. 1) A. Exams 贪心的更多相关文章

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

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

  2. Codeforces Round #274 (Div. 2)-C. Exams

    http://codeforces.com/contest/479/problem/C C. Exams time limit per test 1 second memory limit per t ...

  3. Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟

    http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...

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

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

  5. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

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

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

  7. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  8. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  9. Codeforces Round #274 (Div. 2)

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

随机推荐

  1. Spring学习之基本概念

    Spring 基本概念 Spring优点: 1.Spring不同于其它的Framework,它要提供的是一种管理你的业务对象的方法. 2.DI有效的降低了耦合度 3.AOP提供了通用任务的集中管理 4 ...

  2. 【转】第一次使用Android Studio时你应该知道的一切配置(三):gradle项目构建

    原文网址:http://www.cnblogs.com/smyhvae/p/4456420.html [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.c ...

  3. 【转】iPhone屏幕尺寸、分辨率及适配

    原文网址:http://blog.csdn.net/phunxm/article/details/42174937 1.iPhone尺寸规格 设备 iPhone 宽 Width 高 Height 对角 ...

  4. Android-AnimationDrawable(二)

    首先可以先定义一个逐帧播放的xml: <?xml version="1.0" encoding="utf-8"?> <animation-li ...

  5. Apache:如何利用.htaccess文件对PHP网站或文件进行伪静态处理

    来源:http://www.ido321.com/1123.html 今天get了一招:利用.htaccess文件对PHP网站或文件进行伪静态处理. 一.检查服务器是否支持伪静态处理: 必 须要空间支 ...

  6. Chapter3:字符串、向量和数组

    C++11新特性:范围for(range for) for (declaration: expression) statement vector和数组都是对象的集合,而引用不是对象. vector对象 ...

  7. mybatis系列-10-一对一查询

    10.1     需求 查询订单信息,关联查询创建订单的用户信息 10.2     resultType 10.2.1      sql语句 确定查询的主表:订单表 确定查询的关联表:用户表 关联查询 ...

  8. Tkinter教程之Button篇(1)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811298 #Tkinter教程之Button篇(1)#Button功能触发事件'''1.一个 ...

  9. Linux中MySQL5.5解压版普通用户安装

    #查看本机mysql 安装路径 [hadoop@SY-0134 toolkit]$ rpm -qa|grep -i mysql [hadoop@SY-0134 toolkit]$ whereis my ...

  10. Chapter 2 创建一个应用

    App Engine开发模式如下一般简单<1.The App Engine development model is as simple as it gets:>: 1.创建这个应用 2. ...