Editorial for LCC '21 Contest 1 J5 - Penelope's Pumpkins


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: nicoella

For the first and second subtask, a simple greedy method can be used to search for which pumpkins Penelope should take home which would give the minimum cost.

For the third subtask, a brute-force method can be used to search for which pumpkins Penelope can take home and finding the minimum cost out of all combinations.

For the full solution, if Penelope places a pumpkin of type T_i at indexes j, j + (X + 1), j + 2 \times (X + 1) and so on, assuming N is divisible by X, she can place each type of pumpkin up to a maximum of \lfloor \frac{K}{X+1} \rfloor times. If N is not divisible by X, she can place K % (X+1) pumpkins 1 more time. Greedily search for the smallest values, without taking K % (X+1) pumpkins of a single type more than \lfloor \frac{K}{X+1} \rfloor + 1 times and the remaining pumpkins of a single type more than \lfloor \frac{K}{X+1} \rfloor times.


Comments

There are no comments at the moment.