Table of contents
topic
Now you are running for the mayor of a county. You went and polled every voter. You already know who each person is going to vote for and how much it will cost to get that person to choose you. Now you want to spend the least amount of money to make yourself the county magistrate. The condition for your election is that you have more votes than any other candidate (strictly more, not equal to the most of them). Please calculate the minimum cost.
enter
A single set of test data.
The first line has an integer (1≤n≤10^5) representing the number of voters in this county.
Then there are n lines, and each line has two integers ai and bi(0≤ai≤10^5;0≤bi≤10^4), which means that the i-th voter is the ai-th candidate. He chooses to spend bi's money by himself. You are candidate 0 (so, if a voter votes for you, ai is 0, and bi must be 0 at this time).output
Output an integer representing the least amount of money spent.
Example 1:
enter:
5
1 2
1 2
1 2
2 1
0 0output:
3
train of thought
1: This question is very difficult, and I searched a lot of solutions on the Internet