Election Time
InterviewTime limit1sMemory limit128 MB
Each cow has first round votes A and second round votes B; the top K by A advance, then the one with the largest B among them wins. Output the winner's index.
- Level
Medium4 of 10
- Topics
- Sorting, Array, Greedy, Implementation
- Solved
- No attempts yet
Problem
The cows are holding their first presidential election after overthrowing the tyrannical Farmer John, and Bessie is one of cows () running for President. Before the election actually takes place, Bessie wants to figure out who has the best chance of winning.
The election is held in two rounds. In the first round, the cows () with the most votes advance to the second round. In the second round, the cow with the most votes becomes President.
Cow is expected to receive votes () in the first round and votes () in the second round (if it advances). Determine the index of the cow that is expected to win the election. No two values in the list of are equal, and likewise no two values in the list of are equal.
Input
- Line 1: Two space-separated integers and .
- Lines 2 to : Line contains two space-separated integers and , describing cow .
Output
- Line 1: The index of the cow that is expected to win the election.