IBMOA #41
Get Potential of Winner
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationIn-place Arrays
The two players at the front of the queue play a match; the one with greater potential stays at the front, and the loser goes to the back. The first player to win k games in a row wins; return that player's potential. All potentials are distinct.
Input
The first line contains n k, and the second line contains a permutation of potentials. 2≤n≤100000, potentials are distinct and in 1..n, 2≤k≤10^14.
Output
Output one integer, the answer.
Example 1
Input:
4 2
3 2 1 4
Output:
3
Example 2
Input:
5 2
1 3 2 4 5
Output:
3
Example 3
Input:
4 3
3 2 1 4
Output:
4
Example notes
The examples give 3, 3 and 4 respectively.
Editorial
Loading solution…