cswork / OA打开练习工作台

IBMOA #41

Get Potential of Winner

估计中等可在线判题

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

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.

输入格式

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 one integer, the answer.

样例 1

输入:

4 2
3 2 1 4

输出:

3

样例 2

输入:

5 2
1 3 2 4 5

输出:

3

样例 3

输入:

4 3
3 2 1 4

输出:

4

样例说明

The examples give 3, 3 and 4 respectively.