Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <map>
- #include <set>
- #include <stack>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- #define ll long long
- #define nl "\n"
- #define cy cout << "YES\n"
- #define cn cout << "NO\n"
- #define sz(s) s.size()
- #define all(v) v.begin(), v.end()
- #define cin(vec) for (int i = 0; i < n && cin >> vec[i]; i++)
- #define cout(vec) for (int i = 0; i < n && cout << vec[i] << " "; i++)
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- void solve()
- {
- int n;
- cin >> n;
- int arr[n + 5]{};
- stack<int> st;
- for (int i = 0; i < n; i++)
- {
- int num;
- cin >> num;
- for (int j = 1; j <= num; j++)
- {
- if (arr[j] == 0)
- {
- st.push(j);
- arr[j] = 1;
- }
- }
- if (st.top() == num)
- {
- st.pop();
- }
- else
- {
- cn;
- return;
- }
- }
- cy;
- }
- /*
- */
- int main()
- {
- sherry();
- int t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement