codeforces-scrape

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

1118D1.md (3660B)


      1 Source: https://codeforces.com/problemset/problem/1118/D1
      2 
      3 D1. Coffee and Coursework (Easy version)
      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 The only difference between easy and hard versions is the constraints.
     22 
     23 Polycarp has to write a coursework. The coursework consists of $m$ pages.
     24 
     25 Polycarp also has $n$ cups of coffee. The coffee in the $i$-th cup has $a_i$ caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
     26 
     27 Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
     28 
     29 Let's consider some day of Polycarp's work. Consider Polycarp drinks $k$ cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are $a_{i_1}, a_{i_2}, \dots, a_{i_k}$. Then the first cup he drinks gives him energy to write $a_{i_1}$ pages of coursework, the second cup gives him energy to write $max(0, a_{i_2} - 1)$ pages, the third cup gives him energy to write $max(0, a_{i_3} - 2)$ pages, ..., the $k$-th cup gives him energy to write $max(0, a_{i_k} - k + 1)$ pages.
     30 
     31 If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
     32 
     33 Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
     34 
     35 Input
     36 
     37 The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 10^4$) — the number of cups of coffee and the number of pages in the coursework.
     38 
     39 The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the caffeine dosage of coffee in the $i$-th cup.
     40 
     41 Output
     42 
     43 If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 5 8
     51 2 3 1 1 2
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 4
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 7 10
     64 1 3 4 2 1 4 2
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 2
     71 ```
     72 
     73 Input
     74 
     75 ```
     76 5 15
     77 5 5 5 5 5
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 1
     84 ```
     85 
     86 Input
     87 
     88 ```
     89 5 16
     90 5 5 5 5 5
     91 ```
     92 
     93 Output
     94 
     95 ```
     96 2
     97 ```
     98 
     99 Input
    100 
    101 ```
    102 5 26
    103 5 5 5 5 5
    104 ```
    105 
    106 Output
    107 
    108 ```
    109 -1
    110 ```
    111 
    112 Note
    113 
    114 In the first example Polycarp can drink fourth cup during first day (and write $1$ page), first and second cups during second day (and write $2 + (3 - 1) = 4$ pages), fifth cup during the third day (and write $2$ pages) and third cup during the fourth day (and write $1$ page) so the answer is $4$. It is obvious that there is no way to write the coursework in three or less days in this test.
    115 
    116 In the second example Polycarp can drink third, fourth and second cups during first day (and write $4 + (2 - 1) + (3 - 2) = 6$ pages) and sixth cup during second day (and write $4$ pages) so the answer is $2$. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
    117 
    118 In the third example Polycarp can drink all cups of coffee during first day and write $5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15$ pages of coursework.
    119 
    120 In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write $5 + (5 - 1) + (5 - 2) + (5 - 3) = 14$ pages of coursework and during second day he will write $5$ pages of coursework. This is enough to complete it.
    121 
    122 In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.