-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1012.cpp
More file actions
58 lines (58 loc) · 1019 Bytes
/
1012.cpp
File metadata and controls
58 lines (58 loc) · 1019 Bytes
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
#include <bits/stdc++.h>
using namespace std;
deque<int> A, station, fix;
int indexof(deque<int> d, int item)
{
for (int i = 0; i < d.size(); i++)
{
if (d[i] == item)
{
return i;
}
}
return -1;
}
int main(void)
{
int N, M, want[10];
scanf("%d%d", &N, &M);
for (int i = 0; i < N; i++)
scanf("%d", &want[i]);
for (int i = 1; i <= N; i++)
A.push_back(i);
for (int i = 1; i <= N; i++)
{ //i_th car
int cur = want[i - 1];
int index;
if ((index = indexof(A, cur)) != -1)
{
for (int j = 0; j <= index - 1; j++)
{
station.push_front(A.front());
A.pop_front();
}
A.pop_front();
}
else if ((index = indexof(station, cur)) != -1)
{
for (int j = 0; j <= index - 1; j++)
{
fix.push_front(station.front());
station.pop_front();
}
if (fix.size() > M)
{
puts("no");
return 0;
}
station.pop_front();
for (int j = 0; j < fix.size(); j++)
{
station.push_front(fix.front());
fix.pop_front();
}
}
}
puts("yes");
return 0;
}