Election Time

Interview

Time limit1sMemory limit128 MB

Summary
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 NN cows (1≤N≤500001 \le N \le 50000) 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 KK cows (1≤K≤N1 \le K \le N) with the most votes advance to the second round. In the second round, the cow with the most votes becomes President.

Cow ii is expected to receive AiA_i votes (1≤Ai≤10000000001 \le A_i \le 1000000000) in the first round and BiB_i votes (1≤Bi≤10000000001 \le B_i \le 1000000000) 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 AiA_i are equal, and likewise no two values in the list of BiB_i are equal.

Input

  • Line 1: Two space-separated integers NN and KK.
  • Lines 2 to N+1N+1: Line i+1i+1 contains two space-separated integers AiA_i and BiB_i, describing cow ii.

Output

  • Line 1: The index of the cow that is expected to win the election.

Examples1

  1. Example 1

    Input
    5 3
    3 10
    9 2
    5 6
    8 4
    6 5
    
    Expected output
    5