Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include<ext/pb_ds/assoc_container.hpp>
- #include<ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define ll long long
- #define pb push_back
- #define mp make_pair
- #define endl '\n'
- typedef vector<ll> vl;
- typedef long int int32;
- typedef unsigned long int uint32;
- typedef long long int int64;
- typedef unsigned long long int uint64;
- #define all(x) x.begin(), x.end()
- inline void solve(){
- ll n;cin >> n;
- vl v(n);
- rep(i,0,n){
- cin >> v[i];
- }
- ll trash;cin >> trash;
- stack<int> st;
- for(int i = 0;i < n;i++){
- while(!st.empty() && (st.top() > v[i])){
- st.pop();
- }
- st.push(v[i]);
- }
- vl pos(1005);
- vl ans;
- while(!st.empty()){
- ans.pb(st.top());
- pos[st.top()] = 1;
- st.pop();
- }
- reverse(all(ans));
- for(ll i = n - 1;i >= 0;i--){
- if(pos[v[i]] == 1){
- continue;
- }
- else ans.pb(v[i]);
- }
- cout << ((is_sorted(all(ans)) ? "yes" : "no"));
- }
- int main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t = 1;
- // cin >> t
- while (t--){
- solve();
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement