cswork / OA打开练习工作台

JPMorgan ChaseOA #25

Chess Tournament

估计中等可在线判题

考点(AI 标注)模拟/实现原地数组

Players line up in their original order. The two players at the front compare their distinct potentials; the larger one wins and stays at the front, and the loser goes to the back. The process ends as soon as someone first wins k games in a row; output the winner's potential.

输入格式

The first line contains n k, followed by n distinct potentials. Original bounds: N/A. This site uses 2≤n≤200000, 1≤k≤10^18, and potentials are integers in −10^9..10^9; they are not required to be a permutation of 1..n.

输出格式

Output a single integer answer.

样例 1

输入:

4 2
3 2 1 4

输出:

3

样例 2

输入:

4 1
-5 -2 -3 -1

输出:

-2

样例 3

输入:

5 2
1 3 2 4 5

输出:

3

样例说明

The outputs of the three public examples are, in order: 3; -2; 3. These answers have been checked by independent enumeration or direct simulation.