codeforces-scrape

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

730G.md (2710B)


      1 Source: https://codeforces.com/problemset/problem/730/G
      2 
      3 G. Car Repair Shop
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
     22 
     23 Polycarp is good at marketing, so he has already collected *n* requests from clients. The requests are numbered from 1 to *n* in order they came.
     24 
     25 The *i*-th request is characterized by two values: *s**i* — the day when a client wants to start the repair of his car, *d**i* — duration (in days) to repair the car. The days are enumerated from 1, the first day is tomorrow, the second day is the day after tomorrow and so on.
     26 
     27 Polycarp is making schedule by processing requests in the order from the first to the *n*-th request. He schedules the *i*-th request as follows:
     28 
     29 * If the car repair shop is idle for *d**i* days starting from *s**i* (*s**i*, *s**i* + 1, ..., *s**i* + *d**i* - 1), then these days are used to repair a car of the *i*-th client.
     30 * Otherwise, Polycarp finds the first day *x* (from 1 and further) that there are *d**i* subsequent days when no repair is scheduled starting from *x*. In other words he chooses the smallest positive *x* that all days *x*, *x* + 1, ..., *x* + *d**i* - 1 are not scheduled for repair of any car. So, the car of the *i*-th client will be repaired in the range [*x*, *x* + *d**i* - 1]. It is possible that the day *x* when repair is scheduled to start will be less than *s**i*.
     31 
     32 Given *n* requests, you are asked to help Polycarp schedule all of them according to the rules above.
     33 
     34 Input
     35 
     36 The first line contains integer *n* (1 ≤ *n* ≤ 200) — the number of requests from clients.
     37 
     38 The following *n* lines contain requests, one request per line. The *i*-th request is given as the pair of integers *s**i*, *d**i* (1 ≤ *s**i* ≤ 109, 1 ≤ *d**i* ≤ 5·106), where *s**i* is the preferred time to start repairing the *i*-th car, *d**i* is the number of days to repair the *i*-th car.
     39 
     40 The requests should be processed in the order they are given in the input.
     41 
     42 Output
     43 
     44 Print *n* lines. The *i*-th line should contain two integers — the start day to repair the *i*-th car and the finish day to repair the *i*-th car.
     45 
     46 Examples
     47 
     48 Input
     49 
     50 ```
     51 3  
     52 9 2  
     53 7 3  
     54 2 4
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 9 10  
     61 1 3  
     62 4 7
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 4  
     69 1000000000 1000000  
     70 1000000000 1000000  
     71 100000000 1000000  
     72 1000000000 1000000
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 1000000000 1000999999  
     79 1 1000000  
     80 100000000 100999999  
     81 1000001 2000000
     82 ```