Editorial for Wesley's Anger Contest 4 Problem 2 - Squirrel Election
Submitting an official solution before solving the problem yourself is a bannable offence.
Since the number of votes needed to take any province is always the same, it's always optimal to take the provinces with the greatest number of points.
Thus, a greedy solution suffices for this subtask.
Let be the minimum cost needed to secure points using the first provinces. can be defined recursively as with a base case of .
The final answer is simply .
Another similar problem: Knapsack 2
It is also possible to blackbox the knapsack algorithm used in Knapsack 1 by having the value of the items be equal to and the weight of the items equal . The answer in this case is equal to: