cin=lambda:list(map(int,input().split()))
n,k=cin()
A=cin()
C=[0 for i in range(n+1)]
while True:
if A[0]>A[1]:
A[0],A[1]=A[1],A[0]
A=A[1:]+A[:1]
C[A[0]]+=1
if A[0]==n or C[A[0]]>=k:
print(A[0])
break
#include<bits/stdc++.h>
#define ll unsigned long long
#define endl '\n'
using namespace std;
int main()
{
ll n,k;
cin>>n>>k;
ll a[n];
cin>>a[0];
ll max1=a[0];
for(int i=1;i<n;i++)
{
cin>>a[i];
if(a[i]>max1)
max1=a[i];
}
if(k>=n-1)
cout<<max1<<endl;
else
{
int s=a[0],win=0;
for (int i = 1; i < n && win < k; i++)
{
if (a[i] > s)
{
s = a[i];
win = 1;
}
else
{
win++;
}
}
cout<<s<<endl;
}
}
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |
Missing numbers | Maximum sum |
13 Reasons Why | Friend's Relationship |
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |