Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<stack>
  4. using namespace std;
  5.  
  6. struct Point
  7. {
  8.     int from;
  9.     int vagon;
  10. };
  11.  
  12. int main()
  13. {
  14.     int n;
  15.     cin >> n;
  16.     vector<int> v(n);
  17.     for(int i = 0; i < n; ++i) cin >> v[i];
  18.     stack<int> way_1;
  19.     stack<int> stop;
  20.     stack<int> way_2;
  21.     vector<pair<int, int> > ans;
  22.     ans[i].second =
  23.     for(int i = n - 1; i >= 0; i--) way_1.push(v[i]);
  24.     int i = 1;
  25.     int x;
  26.     while(way_1.size() > 0)
  27.     {
  28.         while(way_1.top() != i)
  29.         {
  30.             x = way_1.top();
  31.             stop.push(x);
  32.             way_1.pop();
  33.         }
  34.         x = way_1.top();
  35.         way_2.push(x);
  36.         way_1.pop();
  37.         i++;
  38.         while(stop.top() == i)
  39.         {
  40.             x =  stop.top();
  41.             way_2.push(x);
  42.             stop.pop();
  43.             i++;
  44.         }
  45.     }
  46.     if(way_2.size() == n) cout << "YES";
  47.     else cout << "NO";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement