Editorial for DMOPC '14 Contest 5 P4 - Kittan's Dilemma


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

The idea behind this problem is to notice that the value P \in [1, 2] will hold. You can store all of the 'Good' and 'Bad' Gunmen into two separate lists. After sorting both lists, we can precompute the prefix sum of the combined space up to each Gunmen that will be occupied.

For each index in the two prefix sum lists, we can subtract the value at the index from M and binary search the other list for this difference. The maximum value of the sum of that new index and the original index over all of the index combinations would be the number of Gunmen employed.

Time Complexity: \mathcal{O}(N \log N)


Comments

There are no comments at the moment.