#P4520. Football Association Presidential Election
Football Association Presidential Election
Football Association Presidential Election
In a country with a well‐developed democracy, presidential elections for the football association are held. The country is divided into N counties, each with its own football association. There are M candidates labeled from 1 to M. Each county casts exactly one vote for the candidate highest on their preference list who has not revoked his candidacy. The candidate with the highest number of votes wins; in the case of a tie, the candidate with the smallest label wins.
During the campaign, every county decides on a complete order of preference for the candidates. For instance, if a county’s order is 2, 1, 4, 3 then it will vote for candidate 2 unless candidate 2 revokes their candidacy; if candidate 2 revokes, it will vote for candidate 1 provided candidate 1 is still in the race; and so on.
Zdravko, a passionate football fan and a close friend of candidate K, wants to know two things:
- Who will win the election if no candidate revokes their candidacy?
- What is the minimal number of candidates that must revoke their candidacy in order for candidate K to win?
It is guaranteed that candidate K will never revoke his candidacy.
inputFormat
The first line contains three integers: N, M, and K, where N is the number of counties, M is the number of candidates, and K is the label of Zdravko's friend.
Each of the following N lines contains a permutation of the numbers from 1 to M, representing the order of preference for the county's vote.
outputFormat
Output two lines:
- The first line should contain the label of the winning candidate when no one revokes their candidacy.
- The second line should contain the minimal number of candidates that need to revoke their candidacy to make candidate K the winner.
Note: In case of a tie in votes, the candidate with the smallest label wins.
sample
1 4 2
2 1 4 3
2
0
</p>