Editorial for ICPC PACNW 2016 J - Shopping
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
First, this problem is equivalent to a cumulative mod over a range (that is, we take
This shows that any one shopper can buy at most
We can solve this by reducing it to the subproblem: given a range
Alternatively, we can also solve this using a heap and processing items left to right.
Comments