can anybody explain me this... i am not getting the implementation..2024B - Buying Lemonade
# | User | Rating |
---|---|---|
1 | jiangly | 3845 |
2 | tourist | 3798 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3589 |
6 | Ormlis | 3532 |
7 | Benq | 3468 |
8 | Radewoosh | 3463 |
9 | ecnerwala | 3451 |
10 | Um_nik | 3450 |
# | User | Contrib. |
---|---|---|
1 | cry | 165 |
2 | Qingyu | 159 |
3 | -is-this-fft- | 158 |
4 | atcoder_official | 157 |
5 | Dominater069 | 156 |
6 | adamant | 154 |
7 | djm03178 | 151 |
8 | luogu_official | 150 |
9 | awoo | 148 |
10 | maomao90 | 145 |
can anybody explain me this... i am not getting the implementation..2024B - Buying Lemonade
Name |
---|
we have to find the minimum number of presses (which would determine that k cans will be collected) so if we say that x is the answer then we can say for sure that in the worst luck possible(in the case when you will press the buttons which corresponds the the minimum number of cans) x would work and any case where it's not the worst order x will suffice.
for ex : if the cans are ( 2 1 3 4 ) and we need k=4 cans whats the worst that could happen you press the button with 2nd row and get (2 0 3 4) then press it again and you don't get any so you know that this button is not good , then you press the button corresponding to 2(1st position) in the row so after 2 presses we get (0 0 3 4) then after pressing this for one more time you get the know that this button's row is also empty so you move forward .**so in this case the answer is 6 for getting k=4 , in any other order of presses you would take less than or equal to these number of presses **
**please keep in mind this solution would be complete if the number of cans can be 0 but it is not but we can modify if so it works **
for that just subtract n from k and reduce every element in array by 1 we would have that now number of cans can be zero also
so you can now greedy for the worst case possible .
greedy : we know that a[i] is atleast 1 so we press every button 1 time and reduce every element in array by one. and then follow the procedure above
if you want i can write a simple code for it if you still have some doubts