-
Notifications
You must be signed in to change notification settings - Fork 0
/
1051.cpp
58 lines (56 loc) · 1.4 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <cstdio>
#include <stack>
using namespace std;
int main(){
int m, n, k;
int sq[1010];
scanf("%d %d %d", &m, &n, &k);
for(int i = 0; i < k; i++){
stack<int> s;
int max = n + 1;
for(int j = 0; j < n; j++){
scanf("%d", &sq[j]);
}
bool flag = true;
for(int j = n - 1; j >= 0; j--){
if(!s.empty()){
if(sq[j] > s.top()){
if(s.size() < m){
s.push(sq[j]);
}
else{
flag = false;
break;
}
}
else if(s.top() < max){
max = s.top();
s.pop();
while(!s.empty() && s.top() > sq[j]){
if(s.top() > max){
flag = false;
break;
}
max = s.top();
s.pop();
}
s.push(sq[j]);
}
else{
flag = false;
break;
}
}
else{
s.push(sq[j]);
}
}
if(flag){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return 0;
}