zoukankan      html  css  js  c++  java
  • cf479C Exams

    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.

    排序完取小于now的最小的

     1 #include<cstdio>  
     2 #include<iostream>  
     3 #include<cstring>  
     4 #include<cstdlib>  
     5 #include<algorithm>  
     6 #include<cmath>  
     7 #include<queue>  
     8 #include<deque>  
     9 #include<set>  
    10 #include<map>  
    11 #include<ctime>  
    12 #define LL long long  
    13 #define inf 0x7ffffff  
    14 #define pa pair<int,int>  
    15 #define pi 3.1415926535897932384626433832795028841971  
    16 using namespace std;  
    17 struct classes{  
    18     LL a,b;  
    19 }a[1000000];  
    20 LL n,now;  
    21 bool operator < (classes a,classes b)  
    22 {  
    23     return a.a<b.a||a.a==b.a&&a.b<b.b;  
    24 }  
    25 inline LL read()  
    26 {  
    27     LL x=0,f=1;char ch=getchar();  
    28     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  
    29     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  
    30     return x*f;  
    31 }  
    32 int main()  
    33 {  
    34     n=read();  
    35     for (int i=1;i<=n;i++)  
    36     {  
    37         a[i].a=read();  
    38         a[i].b=read();  
    39     }  
    40     sort(a+1,a+n+1);  
    41     for (int i=1;i<=n;i++)  
    42     {  
    43         if (now>a[i].b)now=a[i].a;  
    44         else now=a[i].b;  
    45     }  
    46     printf("%lld
    ",now);  
    47 }  
    cf479C
    ——by zhber,转载请注明来源
  • 相关阅读:
    HDU6470 ()矩阵快速幂
    O(1)乘法与快速乘O(log)
    imos 学习笔记五 抓拍 c#
    imos 学习笔记四 录像 c#
    imos 学习笔记三 下载指定时间段视频信息 c#
    imos学习笔记二 用户登录c#
    imos学习笔记一 sdk开发环境
    Hbase(nosql)体系结构有基本操作 笔记八
    zookeeper的安装与配置 笔记七
    mapReduce体系结构和各种算法 笔记六
  • 原文地址:https://www.cnblogs.com/zhber/p/4055115.html
Copyright © 2011-2022 走看看