题目链接:

A. 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 nexams. 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.

Examples
input
3
5 2
3 1
4 2
output
2
input
3
6 1
5 2
4 3
output
6

题意:

每课有两次考试时间,老师会按时间靠后的那个记录,要求老师记录的时间不能下降,问你最少需要多少天才能考完;

思路:

b作为第一关键字,a作为第二关键字,从小到大排序,然后贪心;

AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=5e3+10;
const double eps=1e-12; pair<int,int>ha[maxn]; int cmp(pair<int,int> x,pair<int,int> y)
{
if(x.first==y.first)return x.second<y.second;
return x.first<y.first;
}
int main()
{
int n;
read(n);
For(i,0,n-1)
{
read(ha[i].first);
read(ha[i].second);
}
sort(ha,ha+n,cmp);
int ans=0;
for(int i=0;i<n;i++)
{
int temp=min(ha[i].first,ha[i].second);
if(temp<ans)temp=max(ha[i].first,ha[i].second);
ans=temp;
}
cout<<ans<<endl;
return 0;
}

  

最新文章

  1. 如何在mac本上安装android sdk 避免被墙
  2. getFields()和getDeclaredFields()的区别
  3. 在Centos7服务器上搭建网关服务
  4. Nginx/LVS/HAProxy负载均衡软件的优缺点详解(转)
  5. Nhibernate总结(一)查询返回指定字段
  6. 【转】VS 代码行数统计
  7. .getBoundingClientRect()
  8. 重构后的ConditionHelper
  9. java提高篇(六)-----关键字static
  10. PhpStorm创建Drupal模块项目开发教程(5)
  11. Ubuntu配置OpenStack 一:主机环境配置以及问题总结
  12. Lintcode395 Coins in a Line II solution 题解
  13. Android项目实战(四十七):轮播图效果Viewpager
  14. 使用RocketMQ实现分布式事务
  15. 关于mysql的删除和安装
  16. 自学Zabbix9.1 Network Discovery 网络发现原理
  17. js选择排序
  18. Openstack运维指南文档整理
  19. Linux 错误记录
  20. spring mvc ajaxfileupload文件上传返回json下载问题

热门文章

  1. mvc项目架构分享系列之架构搭建初步
  2. SharePoint 2010 文档管理之点击次数
  3. Force.com微信开发系列(八)生成带参数的二维码
  4. oracle断电重启之ORA-01033和ORA-01172
  5. STL--向量(vector)
  6. KVC实现原理简介
  7. 网络开始---多线程---NSThread-02-线程状态(了解)(三)
  8. [windows]利用IPSec对指定的ip进行访问限制
  9. [windows]禁止指定用户使用远程桌面服务登录
  10. Linux与Windows共享文件夹之samba的安装与使用(Ubuntu为例)