n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner.

For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.

Input

The first line contains two integers: n and k (2 ≤ n ≤ 500, 2 ≤ k ≤ 1012) — the number of people and the number of wins.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ai are distinct.

Output

Output a single integer — power of the winner.

Examples
input

Copy
2 2
1 2
output
2 
input

Copy
4 2
3 1 2 4
output
3 
input

Copy
6 2
6 5 3 1 2 4
output
6 
input

Copy
2 10000000000
2 1
output
2
Note

Games in the second sample:

3 plays with 1. 3 wins. 1 goes to the end of the line.

3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.

简单题,注意k很大,当k>n时,输出最大的那个就行

#include <bits/stdc++.h>
using namespace std;
#define maxn 100000
typedef long long ll;
#define inf 2147483647
#define ri register int
vector<ll> vec;
ll p[maxn];
ll cnt[maxn];
ll n, k;
ll ma = ; int main() {
// freopen("test.txt", "r", stdin);
cin >> n >> k;
for (int i = ; i <= n; i++) {
cin >> p[i];
ma = max(ma, p[i]);
vec.push_back(i);
}
if (k > n) {
cout << ma;
return ;
}
while () {
// for(ll i:vec)cout<<i<<" ";
// cout<<endl;
int t1 = vec.front();
vec.erase(vec.begin());
int t2 = vec.front();
vec.erase(vec.begin());
if (p[t1] > p[t2]) {
cnt[t1]++;
if (cnt[t1] == k) {
cout << p[t1];
return ;
}
vec.push_back(t2);
vec.insert(vec.begin(), t1);
} else {
cnt[t2]++;
if (cnt[t2] == k) {
cout << p[t2];
return ;
}
vec.push_back(t1);
vec.insert(vec.begin(), t2);
}
} return ;
}

443 B. Table Tennis的更多相关文章

  1. PAT 1026. Table Tennis

    A table tennis club has N tables available to the public.  The tables are numbered from 1 to N.  For ...

  2. 1026. Table Tennis (30)

    题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...

  3. PAT A1026 Table Tennis (30 分)——队列

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

  4. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题

    C. Table Tennis Game 2 题目连接: http://codeforces.com/contest/765/problem/C Description Misha and Vanya ...

  5. PAT 1026 Table Tennis[比较难]

    1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the public. The tables ar ...

  6. Table Tennis Game 2(找规律)

    Description Misha and Vanya have played several table tennis sets. Each set consists of several serv ...

  7. PAT甲级1026. Table Tennis

    PAT甲级1026. Table Tennis 题意: 乒乓球俱乐部有N张桌子供公众使用.表的编号从1到N.对于任何一对玩家,如果有一些表在到达时打开,它们将被分配给具有最小数字的可用表.如果所有的表 ...

  8. PAT 甲级 1026 Table Tennis(模拟)

    1026. Table Tennis (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table ...

  9. PAT 1026 Table Tennis (30)

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

随机推荐

  1. css的元素表现

    块级元素和行内元素的表现: 块级元素:块级元素和父元素的宽度一致,默认情况下就是和body的宽度一样,也可以说和浏览器窗口的宽度一致,致使同一行不能再放下另外的元素,所以块级元素表现为独占一行. 块级 ...

  2. div+css模拟select下拉框

    <!DOCTYPE html><html ><head lang="zh"> <meta http-equiv="Content ...

  3. ID3决策树算法实现(Python版)

    # -*- coding:utf-8 -*- from numpy import * import numpy as np import pandas as pd from math import l ...

  4. CentOS7系列--1.1CentOS7安装

    CentOS7安装 1. 下载CentOS7 下载的网址为: http://isoredirect.centos.org/centos/7/isos/x86_64/ 2. CentOS7安装 2.1. ...

  5. OpenGL学习--08--基本渲染(灯光)

    1.tutorial08.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> #inc ...

  6. CSS3 选择器用法小结

    表单选择器: /*:enabled 可用的 :disabled 被禁用的 :focus 获取了焦点的 多用在表单元素上*/ input:enabled {...} input:disabled {.. ...

  7. 回归JavaScript基础(四)

    主题:JavaScript变量.作用域和内存问题 JavaScript的变量和别的语言比起来是与众不同的.说道变量,不得不谈他的作用域.同很多语言一样,JavaScript开发者也不用担心开发中内存的 ...

  8. LeetCode题解之Unique Morse Code Words

    1.题目描述 2.题目分析 将words 中的每一个string  直接翻译成对应的Morse 码,然后将其放入 set 中,最后返回set的大小即可,此处利用的set 中元素不重复的性质. 3.代码 ...

  9. B-树特征

    在m阶B-树的定义中,要求: 1.树中每个节点至多有m棵子树. 2.若根节点不是叶子节点,则至少有两棵子树. 3.除根之外的所有非终端节点至少有棵子树.

  10. 转: 根据屏幕分辨率,浏览器调用不同css

    <link type="text/csss" href="" rel="stylesheet"/> <link type= ...