Advertisement
Derga

Untitled

Sep 12th, 2023
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <stack>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int tests_count;
  10.     cin >> tests_count;
  11.     for (int i = 0; i < tests_count; ++i)
  12.     {
  13.         int nums_count;
  14.         cin >> nums_count;
  15.         vector< int > nums(nums_count);
  16.         for (int& num : nums)
  17.         {
  18.             cin >> num;
  19.         }
  20.  
  21.         int l = 0;
  22.         int r = 0;
  23.         stack<int> storage;
  24.         while (l < nums.size()) {
  25.             int min_idx = min_element(begin(nums) + r, end(nums)) - begin(nums);
  26.            
  27.             for (int idx = 0; idx < min_idx; ++idx)
  28.             {
  29.                 int cur_number = nums[idx];
  30.                 if (storage.empty() || storage.top() >= cur_number)
  31.                 {
  32.                     storage.push(cur_number);
  33.                     continue;
  34.                 }
  35.                 cout << 0 << '\n';
  36.                 break;
  37.             }
  38.  
  39.             l = min_idx + 1;
  40.         }
  41.  
  42.     }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement