Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
643 B
1
Indexable
Never
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;

int main() {
    IO;
    int n;
    while (cin >> n, n) {
        int cmp = 1;
        stack<int> stk;
        for (int i = 0; i < n; ++i) {
            int val;
            cin >> val;
            stk.push(val);
            while(!stk.empty() and cmp == stk.top()) {
                stk.pop();
                cmp += 1;
            }
        }
        if (stk.empty()) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }
    return 0;
}
Leave a Comment