codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

479C.md (2733B)


      1 Source: https://codeforces.com/problemset/problem/479/C
      2 
      3 C. Exams
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. 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 *b**i* (*b**i* < *a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. 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 *a**i*.
     24 
     25 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.
     26 
     27 Input
     28 
     29 The first line contains a single positive integer *n* (1 ≤ *n* ≤ 5000) — the number of exams Valera will take.
     30 
     31 Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1 ≤ *b**i* < *a**i* ≤ 109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly.
     32 
     33 Output
     34 
     35 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.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3  
     43 5 2  
     44 3 1  
     45 4 2
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 2
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 3  
     58 6 1  
     59 5 2  
     60 4 3
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 6
     67 ```
     68 
     69 Note
     70 
     71 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.
     72 
     73 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.