codeforces-scrape

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

920B.md (2618B)


      1 Source: https://codeforces.com/problemset/problem/920/B
      2 
      3 B. Tea Queue
      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 Recently *n* students from city S moved to city P to attend a programming camp.
     22 
     23 They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
     24 
     25 *i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
     26 
     27 For each student determine the second he will use the teapot and get his tea (if he actually gets it).
     28 
     29 Input
     30 
     31 The first line contains one integer *t* — the number of test cases to solve (1 ≤ *t* ≤ 1000).
     32 
     33 Then *t* test cases follow. The first line of each test case contains one integer *n* (1 ≤ *n* ≤ 1000) — the number of students.
     34 
     35 Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1 ≤ *l**i* ≤ *r**i* ≤ 5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
     36 
     37 It is guaranteed that for every ![](https://espresso.codeforces.com/05362455b6ad5b6870bcef95c0b20ccb40cc3532.png) condition *l**i* - 1 ≤ *l**i* holds.
     38 
     39 The sum of *n* over all test cases doesn't exceed 1000.
     40 
     41 Note that in hacks you have to set *t* = 1.
     42 
     43 Output
     44 
     45 For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 2  
     53 2  
     54 1 3  
     55 1 4  
     56 3  
     57 1 5  
     58 1 1  
     59 2 3
     60 ```
     61 
     62 Output
     63 
     64 ```
     65 1 2   
     66 1 0 2
     67 ```
     68 
     69 Note
     70 
     71 The example contains 2 tests:
     72 
     73 1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second.
     74 2. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.