Editorial for SAC '21 Code Challenge P2 - Littering

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: maxcruickshanks

Subtask 1

For each piece of garbage you remove, iterate over the remaining elements and remove the maximum value one.

Time Complexity: \mathcal O(NK)

Subtask 2

Instead of looping over the entire array, we can sort it and sum up the first K elements to yield the answer (remember to ensure your data types can handle numbers up to 10^{15}).

Time Complexity: \mathcal O(N \log N + K)


There are no comments at the moment.