-
Notifications
You must be signed in to change notification settings - Fork 0
/
1051.cpp
45 lines (34 loc) · 916 Bytes
/
1051.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
#include <cstdio>
#include <stack>
const int MAXN = 1000 + 10;
int a[MAXN];
int main() {
int maxSize, n, k;
scanf("%d%d%d", &maxSize, &n, &k);
while (k--) {
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
std::stack<int> st;
bool flag = true;
int now = 0;
for (int i = 1; i <= n; i++) {
for (int cnt = now + 1; cnt <= a[i]; cnt++) {
now = cnt;
st.push(cnt);
if (st.size() > maxSize) {
flag = false;
break;
}
}
if (st.top() != a[i]) {
flag = false;
break;
} else st.pop();
if (!flag) break;
}
if (!flag) printf("NO\n");
else printf("YES\n");
}
return 0;
}