codeforces-scrape

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

4B.md (2064B)


      1 Source: https://codeforces.com/problemset/problem/4/B
      2 
      3 B. Before an Exam
      4 
      5 time limit per test
      6 
      7 0.5 second
      8 
      9 memory limit per test
     10 
     11 64 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
     22 
     23 So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours *sumTime* spent him on preparation, and now he wants to know if he can show his parents a timetable *sсhedule* with *d* numbers, where each number *sсhedule**i* stands for the time in hours spent by Peter each *i*-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all *schedule**i* should equal to *sumTime*.
     24 
     25 Input
     26 
     27 The first input line contains two integer numbers *d*, *sumTime* (1 ≤ *d* ≤ 30, 0 ≤ *sumTime* ≤ 240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime**i*, *maxTime**i* (0 ≤ *minTime**i* ≤ *maxTime**i* ≤ 8), separated by a space — minimum and maximum amount of hours that Peter could spent in the *i*-th day.
     28 
     29 Output
     30 
     31 In the first line print YES, and in the second line print *d* numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 1 48  
     39 5 7
     40 ```
     41 
     42 Output
     43 
     44 ```
     45 NO
     46 ```
     47 
     48 Input
     49 
     50 ```
     51 2 5  
     52 0 1  
     53 3 5
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 YES  
     60 1 4
     61 ```