Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<stack>
- using namespace std;
- struct Point
- {
- int from;
- int vagon;
- };
- int main()
- {
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i < n; ++i) cin >> v[i];
- stack<int> way_1;
- stack<int> stop;
- stack<int> way_2;
- vector<pair<int, int> > ans;
- ans[i].second =
- for(int i = n - 1; i >= 0; i--) way_1.push(v[i]);
- int i = 1;
- int x;
- while(way_1.size() > 0)
- {
- while(way_1.top() != i)
- {
- x = way_1.top();
- stop.push(x);
- way_1.pop();
- }
- x = way_1.top();
- way_2.push(x);
- way_1.pop();
- i++;
- while(stop.top() == i)
- {
- x = stop.top();
- way_2.push(x);
- stop.pop();
- i++;
- }
- }
- if(way_2.size() == n) cout << "YES";
- else cout << "NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement