-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstpar.cpp
More file actions
47 lines (47 loc) · 873 Bytes
/
stpar.cpp
File metadata and controls
47 lines (47 loc) · 873 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
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
while(cin>>n) {
if(n==0)
break;
vector<int> A(n),cnt(n+2,0);
for(int i=0;i<n;i++) {
cin>>A[i];
cnt[A[i]]++;
}
stack<int> sl;
for(int i=0;i<A.size();i++) {
sl.push(A[i]);
//cout<<A[i]<<" ";
if(cnt[A[i]-1]==0&&!sl.empty()) {
int a=sl.top();
cnt[a]--;
sl.pop();
while(!sl.empty()) {
int b=sl.top();
if(b==a||b==a+1) {
sl.pop();
a=b;
cnt[a]--;
} else {
break;
}
}
}
}
if(sl.empty())
cout<<"yes\n";
else
cout<<"no\n";
}
return 0;
}