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;
- stack<int> st2;
- for (int i = n; i > 0; i--)
- {
- st2.push(i);
- }
- stack<int> st;
- for (int i = 0; i < n; i++)
- {
- int num;
- cin >> num;
- if (st2.top() <= num)
- {
- cout << num << nl;
- while (st2.top() <= num&&!st2.empty())
- {
- st.push(st2.top());
- st2.pop();
- }
- }
- 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