codeforces-scrape

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

608A.md (1977B)


      1 Source: https://codeforces.com/problemset/problem/608/A
      2 
      3 A. Saitama Destroys Hotel
      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 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
     22 
     23 The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
     24 
     25 Input
     26 
     27 The first line of input contains two integers *n* and *s* (1 ≤ *n* ≤ 100, 1 ≤ *s* ≤ 1000) — the number of passengers and the number of the top floor respectively.
     28 
     29 The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1 ≤ *f**i* ≤ *s*, 1 ≤ *t**i* ≤ 1000) — the floor and the time of arrival in seconds for the passenger number *i*.
     30 
     31 Output
     32 
     33 Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 3 7  
     41 2 1  
     42 3 8  
     43 5 2
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 11
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 5 10  
     56 2 77  
     57 3 33  
     58 8 21  
     59 9 12  
     60 10 64
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 79
     67 ```
     68 
     69 Note
     70 
     71 In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
     72 
     73 1. Move to floor 5: takes 2 seconds.
     74 
     75 2. Pick up passenger 3.
     76 
     77 3. Move to floor 3: takes 2 seconds.
     78 
     79 4. Wait for passenger 2 to arrive: takes 4 seconds.
     80 
     81 5. Pick up passenger 2.
     82 
     83 6. Go to floor 2: takes 1 second.
     84 
     85 7. Pick up passenger 1.
     86 
     87 8. Go to floor 0: takes 2 seconds.
     88 
     89 This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.