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.

Author: Riolku

Subtask 1

If we're going to buy all the characters, it is optimal to buy them in order of non-increasing A_i.

Subtask 2

Knowing that the best ordering is non-increasing A_i, 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 (\text{characters_processed_so_far}, \text{characters_bought_so_far}). 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

There are no comments at the moment.