codeforces-scrape

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

557A.md (3465B)


      1 Source: https://codeforces.com/problemset/problem/557/A
      2 
      3 A. Ilya and Diplomas
      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 Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
     22 
     23 At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.
     24 
     25 They also decided that there must be given at least *min*1 and at most *max*1 diplomas of the first degree, at least *min*2 and at most *max*2 diplomas of the second degree, and at least *min*3 and at most *max*3 diplomas of the third degree.
     26 
     27 After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.
     28 
     29 Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.
     30 
     31 It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all *n* participants of the Olympiad will receive a diploma of some degree.
     32 
     33 Input
     34 
     35 The first line of the input contains a single integer *n* (3 ≤ *n* ≤ 3·106) — the number of schoolchildren who will participate in the Olympiad.
     36 
     37 The next line of the input contains two integers *min*1 and *max*1 (1 ≤ *min*1 ≤ *max*1 ≤ 106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed.
     38 
     39 The third line of the input contains two integers *min*2 and *max*2 (1 ≤ *min*2 ≤ *max*2 ≤ 106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.
     40 
     41 The next line of the input contains two integers *min*3 and *max*3 (1 ≤ *min*3 ≤ *max*3 ≤ 106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.
     42 
     43 It is guaranteed that *min*1 + *min*2 + *min*3 ≤ *n* ≤ *max*1 + *max*2 + *max*3.
     44 
     45 Output
     46 
     47 In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
     48 
     49 The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.
     50 
     51 Examples
     52 
     53 Input
     54 
     55 ```
     56 6  
     57 1 5  
     58 2 6  
     59 3 7
     60 ```
     61 
     62 Output
     63 
     64 ```
     65 1 2 3
     66 ```
     67 
     68 Input
     69 
     70 ```
     71 10  
     72 1 2  
     73 1 3  
     74 1 5
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 2 3 5
     81 ```
     82 
     83 Input
     84 
     85 ```
     86 6  
     87 1 3  
     88 2 2  
     89 2 2
     90 ```
     91 
     92 Output
     93 
     94 ```
     95 2 2 2
     96 ```