Advertisement
paranid5

4_tehnokubok

Oct 25th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie(nullptr);
  9.     cout.tie(nullptr);
  10.    
  11.     int n = 0;
  12.     cin >> n;
  13.  
  14.     vector<pair<int, bool>> nums(n, pair<int, bool>(0, false));
  15.     int size = 0;
  16.     int ind = -1;
  17.  
  18.     for (int g = 0; g < 2 * n; g++)
  19.     {
  20.         char x = 0;
  21.         int y = 0;
  22.  
  23.         cin >> x;
  24.  
  25.         if (x == '-' && size <= 0)
  26.         {
  27.             cout << "NO";
  28.             return 0;
  29.         }
  30.  
  31.         else if (x == '+')
  32.             ind++, size++;
  33.  
  34.         else // -
  35.         {
  36.             size--;
  37.             cin >> y;
  38.            
  39.             if (ind >= n)
  40.             {
  41.             HER: bool del = false;
  42.                
  43.                 for (int i = 0; i < ind; i++)
  44.                 {
  45.                     if (!del && !nums[i].second && nums[i].first >= y)
  46.                     {
  47.                         del = true;
  48.                         nums[i].first = y;
  49.                         nums[i].second = true;
  50.                     }
  51.  
  52.                     else if (del && !nums[i].second)
  53.                         nums[i].first = y + 1;
  54.                 }
  55.  
  56.                 if (!del)
  57.                 {
  58.                     cout << "NO";
  59.                     return 0;
  60.                 }
  61.             }
  62.  
  63.             else
  64.             {
  65.                 if (nums[ind].second)
  66.                     goto HER;
  67.  
  68.                 else
  69.                 {
  70.                     nums[ind].first = y;
  71.                     nums[ind].second = true;
  72.  
  73.                     for (int i = 0; i < ind; i++)
  74.                     {
  75.                         if (!nums[i].second)
  76.                             nums[i].first = max(nums[i].first, y + 1);
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.     }
  82.  
  83.     cout << "YES" << '\n';
  84.  
  85.     for (const auto& i : nums)
  86.         cout << i.first << " ";
  87.  
  88.     return 0;
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement