You are running for a governor in a small city in Russia. You ran some polls and did some research, and for every person in the city you know whom he will vote for, and how much it will cost to bribe that person to vote for you instead of whomever he wants to vote for right now. You are curious, what is the smallest amount of money you need to spend on bribing to win the elections. To win elections you need to have strictly more votes than any other candidate.
Output
Print one integer — smallest amount of money you need to spend to win the elections.
解题报告: 昨晚(准确来说是今天早上)CF上的比赛第三题。前两题1小时多搞定了,这题一直没有想法。比赛后就去睡了。白天看了前几名的代码,然后就有点头绪了。
我们的目标是用最少的钱使自己的票数多余其他人的票数。我们可以直接买票比我们当前票数多的那些人的票,这样我们的票增加了,他们的票减少了;我们也可以直接买最便宜的票,直到超过所有其他人。这样我们可以枚举最后其他人的票最多有多少。减少的票我们都买下来,不够我们就继续买最便宜的。最终取结果的最小值。
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include