hust新人赛模拟20150407 A

A - A

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

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

Input

35 23 14 2

Output

2

Input

36 15 24 3

Output

6

Hint

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.

题意是说一个学生要参加考试,正常第I科的考试是在第a[i]天举行,但是可以提前到b[i]天(b[i]<a[i])去考。

这货是个学神,考试不会不通过,一天也可以参加无限多场考试。

然后考完第I科,老师会在记录本上记下这场考试的实际上的考试日期(也就是说即使我提前在b[i]天考了,老师在记录本上记下的日期仍然是a[i])

要求记录本上的日期(也就是a[i])非减,问最快可以什么时间参加完最后一科考试。

分析:能大概感觉到是个贪心。既然限制是a[i]要非减,那么我们就以a[i]为关键字进行排序。

然后扫一遍,因为每个b[i]都要比a[i]小,所以优先选择让这货在b[i]pass掉第I科目,如果条件不允许,则在a[i]天过掉。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

#include <cmath>

using namespace std;
int n,ans;
const int N=1E4+5;
int a[N],b[N];

struct  Q
{int a,b;
}q[N];

bool cmp(Q x, Q y)
{
    if ( x.a<y.a) return true;
    if ( x.a==y.a &&x.b<y.b ) return true;
    return false;
}

int main()
{
    scanf("%d",&n);
    for ( int i = 1 ; i <= n ; i++ )
        scanf("%d %d",&q[i].a,&q[i].b);
    sort(q+1,q+n+1,cmp);

    ans=q[1].b;
    for ( int i = 2 ; i <= n; i++ )
    {
        if ( q[i].b>=ans )
            ans = q[i].b;
        else ans = q[i].a;
    }
    printf("%d\n",ans);
    return 0;
}
时间: 2024-10-11 13:13:52

hust新人赛模拟20150407 A的相关文章

hust新人赛模拟20150407 F

F - F Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered

hust新人赛模拟 20150407 H

H - H Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ru

【阿里云新人赛】恶意程序检测-项目实践总结

1. 比赛信息 比赛地址:阿里云恶意程序检测新人赛 比赛介绍:使用自然语言处理的方法对恶意程序的行为(API调用序列)进行分析,实现对恶意程序鉴别及分类. 2. 我的主要工作 1)数据预处理:格式转换csv->txt->pkl,根据fileid分组数据,排序后生成api序列,用于训练: 2)数据分析及可视化:主要是数据分布分析,包括恶意程序类别分布分析.调用api的类别及频率分析,训练集与测试集分布差异分析(计算交叉熵)等, 得出结论:此任务训练集与测试集分布差异不大,恶意程序类型更多是与ap

NYOJ-682 小媛在努力 (郑大第六届校赛 模拟)

链接:click here 题意: 描述 在多媒体数据处理中,数据压缩算法尤为重要.小媛上完课后就想自己发明一个数据压缩算法.她想呀想,终于想到一个方法.在多媒体数据中有很多数据都是重复的,所以她想把连续相同的数据用数据出现的次数和数据本身表示.例如:1 1 1 2 3 3 3 3 3  压缩后及为3 1 1 2 5 3(表示3个1,1个2和5个3).有想法后小媛就希望把它用代码实现了.但是大家都知道小媛现在整天都忙着苦B的复习考研,连电脑都摸不到.所以她希望作为ACMer的你帮她写一下. 输入

【题解】PAT团体程序设计天梯赛 - 模拟赛

由于本人愚笨,最后一题实在无力AC,于是只有前14题的题解Orz 总的来说,这次模拟赛的题目不算难,前14题基本上一眼就有思路,但是某些题写起来确实不太容易,编码复杂度有点高~ L1-1 N个数求和 设计一个分数类,重载加法运算符,注意要约分,用欧几里得算法求个最大公约数即可. 1 #include <cstdio> 2 3 long long abs(long long x) 4 { 5 return x < 0 ? -x : x; 6 } 7 8 long long gcd(long

2016年 团体程序设计天梯赛 - 模拟赛

此处有目录↑ L1的题太水了,直接模拟即可,就不贴了 L3-2和L3-3没时间写了(估计也不好写吧...) 比赛网址:https://www.patest.cn/contests/2016gplt-0 交题网址: https://www.patest.cn/contests/gplt L2-1. 集合相似度 (排序) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.

模拟赛 模拟题

1.送分题(ptgiving.cpp/c/pas) [问题背景] ? 众所周知, xkj是GH的得意门生,可是 xkj的数学成绩并不是很理想,每次GH在批评完数学限训做的差的人后,总会在后面加上一句,咱们班还有一位做的最差的同学--xkj,你看看你还有对号吗,居然比cdy做得还差! xkj当然是不服的啦,当场跟GH van♂硬币.在玩完硬币后,生成了一系列随机的乱七八糟的数字,并把他们整列成科学计数法的形式,并排序成有序的序列,还计算出排序的最小成本之后,终于,从桌堂里掏出了一本古老的小黄书--

天池新人赛——快来一起挖掘幸福感!

该赛题使用公开数据的问卷调查结果,选取其中多组变量 包括个体变量(性别.年龄.地域.职业.健康.婚姻与政治面貌等等) 家庭变量(父母.配偶.子女.家庭资本等等) 社会态度(公平.信用.公共服务等等) 来预测其对幸福感的评价 前期处理 将提供的训练数据的幸福度标签独立出来,并将除了幸福度标签的训练数据和待测试的数据合并 这样就省去既要处理训练数据又要处理测试数据的冗余,一次解决 df_train = pd.read_csv("happiness_train_complete.csv",e

SOJ 4445 2015四川省赛模拟题

背景:赛场上就是因为没开这道题,而没拿到银,回来A了,感觉代码能力还是很弱,一定要先想好再敲,而且注重代码的函数化,这样无论是观感,还是调试都要好很多,逻辑要清晰,看代码要仔细,提交之前通读代码. 题意:起点在原点的frog,开始向右运动,且碰到障碍物就右转,问转多少次? 思路:关键是图的大小范围是109,无法存下,只有用类似链表的方法来存图.这里用了两个容器,一个以X为基准,一个一Y为基准,这两个容器设置很特殊,是为了满足题中特殊的查询需要:查询前进方向最近障碍物. 我的代码: #includ