codeforces 47 C. Exams

http://codeforces.com/problemset/problem/479/C

 1/************************************************
 2Author :111qqz
 3Created Time :2016年02月22日 星期一 23时31分10秒
 4File Name :code/cf/problem/479C.cpp
 5************************************************ */
 6
 7#include <iostream>
 8#include <algorithm>
 9#include <cstring>
10#include <cstdio>
11
12#include <cmath>
13
14using namespace std;
15int n,ans;
16const int N=1E4+5;
17int a[N],b[N];
18
19struct  Q
20{int a,b;
21}q[N];
22
23bool cmp(Q x, Q y)
24{
25    if ( x.a<y.a) return true;
26    if ( x.a==y.a &&x.b<y.b ) return true;
27    return false;
28}
29
30int main()
31{
32    scanf("%d",&n);
33    for ( int i = 1 ; i <= n ; i++ )
34        scanf("%d %d",&q[i].a,&q[i].b);
35    sort(q+1,q+n+1,cmp);
36
37    ans=q[1].b;
38    for ( int i = 2 ; i <= n; i++ )
39    {
40        if ( q[i].b>=ans )
41            ans = q[i].b;
42        else ans = q[i].a;
43    }
44    printf("%d\n",ans);
45    return 0;
46}
47
48
49