Editorial for BSSPC '22 P6 - Permutations & Primogems
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.
Author:
Subtask 1
If we're going to buy all the characters, it is optimal to buy them in order of non-increasing .
Subtask 2
Knowing that the best ordering is non-increasing , let's sort by that.
Now, since we're not buying every character, and it's not trivial to determine which characters should be bought and which shouldn't, let's do DP.
Specifically, our state is . Every time we process a character, we can choose whether or not to buy it, and knowing how many characters we've bought so far, we can calculate our total cost.
Comments