-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableTennis.cpp
61 lines (56 loc) · 903 Bytes
/
TableTennis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int main()
{
int n,win;
long long k;
long long count = 0;
std::deque<int> mydeque;
cin>>n>>k;
int max = 0;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
max = std::max(max,a[i]);
mydeque.push_back(a[i]);
}
if(k>=n)
cout<<max<<endl;
else
{
while(!mydeque.empty() && count<k)
{
int m,n;
m = mydeque.front();
mydeque.pop_front();
if(!mydeque.empty())
{
n = mydeque.front();
mydeque.pop_front();
}
if(mydeque.empty())
{
win = m>n?m:n;
break;
}
if(m>n)
{
count+=1;
mydeque.push_back(n);
mydeque.push_front(m);
win=m;
}
else
{
count=1;
mydeque.push_back(m);
mydeque.push_front(n);
}
}
cout<<win<<endl;
}
return 0;
}