ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Kovrov IT > задача:


165. 50360 - National Elections

Гость
• Вопросы к жюри (1)

Задачи сборника

• 50342 - 100 Factorial
• 50337 - Exam Averages
• 51149 - One Piece Arena
• 50558 - Hangari i madh [USACO FA...
• 50567 - Normalizimi Min Max
• 50769 - Ku eshte Waldorf?
• 151. 50557 - Fuqia e N-te e M(Shu...
• 160. 50301 - Fractions to Decimals
• 165. 50360 - National Elections
• 170. 50319 - Toll Plazas
• 210. 50361 - Align Two Lists

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 4000/7000/7000/7000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Ibrahim Mesecan.

National Elections

Babylonia Republic is going to have national elections this year. National Elections Organization Committee (NEOC) wants to use a computerized election system. During the elections they have stored all votes of all people with their IDs and the Candidate ID that he has voted for.

The following rules apply for the elections:

  • A voter may vote several times. Only his last vote is valid.
  • A vote is invalid, if it's zero (0) or if the voter didn't vote for anybody
NEOC wants the system to count the votes and to calculate the winner of the elections automatically. They also want to see the number of invalid votes. Write a program that is going to read the votes and calculate the winner.

Input specification
The first line contains two numbers: the number of voters (n) and the number of candidates (m) where 2 ≤ m ≤ 50 and 2 ≤ n ≤ 100000. Each of the following n lines contains two numbers: the id of the voter (j), and to whom he has voted for (k), where 1 ≤ j ≤ n and 0 ≤ k ≤ m.

Output specification
Show two numbers: candidate ID of the winner and the number of invalid votes.

Sample Input:
5 3
1 2
5 0
2 3
4 1
1 3

Sample Output:
3 2

Input Explanation:
There are 5 voter and 3 candidates:

  • Voter 1 has first voted for 2, then he has changed mind and decided to vote for Candidate 3
  • Voter 2 has voted for Candidate 3
  • Voter 3 hasn't voted for anybody, thus he has invalid vote.
  • Voter 4 has voted for Candidate 1
  • Voter 5 has voted for 0 (invalid vote)

Output Explanation: Candidate 3 has won the elections and there are 2 invalid votes.

Sample Input:
20 5
6 2
13 4
4 2
16 1
19 4
20 1
13 1
1 3
4 4
1 2
4 3
16 4
6 4
4 2
7 5
19 2
14 4
3 1
20 5
3 4

Sample Output:
4 10

Для отправки решений необходимо выполнить вход.

www.contester.ru