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

时间:2022-05-28 18:21:18

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 &num;274 &lpar;Div&period; 2&rpar; C&period; Exams &lpar;贪心&rpar;

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

  2. Codeforces Round &num;274 &lpar;Div&period; 2&rpar;-C&period; Exams

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

  3. Codeforces Round &num;377 &lpar;Div&period; 2&rpar; D&period; Exams 贪心 &plus; 简单模拟

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

  4. Codeforces Round &num;377 &lpar;Div&period; 2&rpar; D&period; Exams

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

  5. Codeforces Round &num;202 &lpar;Div&period; 1&rpar; A&period; Mafia 贪心

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

  6. Codeforces Round &num;274 &lpar;Div&period; 2&rpar; 解题报告

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

  7. Codeforces Round &num;382 &lpar;Div&period; 2&rpar;B&period; Urbanization 贪心

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

  8. Codeforces Round &num;164 &lpar;Div&period; 2&rpar; E&period; Playlist 贪心&plus;概率dp

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

  9. Codeforces Round &num;274 &lpar;Div&period; 2&rpar;

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

随机推荐

  1. 20145218 《Java程序设计》第05次实验报告

    北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1452 指导教师:娄嘉鹏 实验名称:Java网络编程及安全 一.实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使 ...

  2. 山东省第五届ACM省赛

    题目链接:http://acm.sdut.edu.cn/sdutoj/contest_show.php?contest_id=1449 相关总结:http://www.cnblogs.com/mcfl ...

  3. 使用Thread类可以创建和控制线程

    1.创建线程 static void Main(string[] args) { /* Thread类 * 创建控制线程 * 其构造函数接受ThreadStart和ParameterizedThrea ...

  4. JavaWeb项目开发案例精粹-第3章在线考试系统-003Dao层

    1. package com.sanqing.dao; import java.util.List; import com.sanqing.po.Student; public interface S ...

  5. windows访问linux共享

    1. 安装samba yum install  samba 2. 配置samba配置文件,添加共享文件夹 vim   /etc/samba/smb.conf 3. 关闭selinux vi  /etc ...

  6. JQuery 插件之Ajax Autocomplete(ajax自动完成)

    平时用百度,谷歌搜索的时候 会有一个下 拉列表进行提示 这是一个非常好的功能 本文要介绍的这个JQuery 插件 名叫Ajax Autocomplete 顾名思义 ajax 也就是用ajax的方式获取 ...

  7. 算法模板——KMP字符串匹配

    功能:输入一个原串,再输入N个待匹配串,在待匹配串中找出全部原串的起始位置 原理:KMP算法,其实这个东西已经包含了AC自动机的思想(fail指针/数组),只不过适用于单模板匹配,不过值得一提的是在单 ...

  8. es6学习笔记--解构赋值

    昨天学习了es6语法中解构赋值,解构赋值在声明中和函数传参提高了灵活性和便捷性,值得掌握该语法. 概念: ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构.   数组的解构 ...

  9. Django创建自定义错误页面400&sol;403&sol;404&sol;500等

    直接参考: https://zhuanlan.zhihu.com/p/38006919 DEBUG =True的话,为开发环境,显示不了404页面.

  10. Window Batch编程示例

    日期时间相关示例 将下面的代码保存为批处理文件 ,命名为GetDate.bat 可以在另外的批处理文件中call GetDate.bat,并直接使用GetDate.bat里面定义的变量,如下图所示: ...