-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1051.cpp
35 lines (34 loc) · 815 Bytes
/
A1051.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
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main()
{
int s,n,k;
cin >> s >> n >> k;
int now;
vector<bool> v;
while(k--) {
vector<int> l;
bool flag = true;
for(int i = 1;i <= n; i++) {
cin >> now;
l.push_back(now);
}
stack<int> st;
int num=1;
for(int i = 0;i < n; i++) {
while(num<=n&&(st.empty()||st.top()!=l[i])){
st.push(num++);
}
// cout << "st.size():" << st.size()<<endl;
if(st.size()>s) {flag=false;break;}
if (st.top()==l[i]) {
st.pop();
} else {flag = false;break;}
}
if(flag) cout<< "YES"<<endl;
else cout<< "NO"<<endl;
}
return 0;
}