Preparando MOJI

Elections

2000ms 262144K

Description:

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.

Input:

First line contains one integer n (1 ≤ n ≤ 105) — number of voters in the city. Each of the next n lines describes one voter and contains two integers ai and bi (0 ≤ ai ≤ 105; 0 ≤ bi ≤ 104) — number of the candidate that voter is going to vote for and amount of money you need to pay him to change his mind. You are the candidate 0 (so if a voter wants to vote for you, ai is equal to zero, in which case bi will also be equal to zero).

Output:

Print one integer — smallest amount of money you need to spend to win the elections.

Sample Input:

5
1 2
1 2
1 2
2 1
0 0

Sample Output:

3

Sample Input:

4
1 2
1 2
2 1
0 0

Sample Output:

2

Sample Input:

1
100000 0

Sample Output:

0

Informação

Codeforces

Provedor Codeforces

Código CF457C

Tags

brute force

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 08:53:10

Relacionados

Nada ainda