Advertisement
mfgnik

Untitled

Jun 28th, 2020
1,604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <tuple>
  4.  
  5. int main() {
  6.     int amount;
  7.     std::cin >> amount;
  8.     std::vector<int> dead_end;
  9.     std::vector<std::tuple<int, int>> actions;
  10.     int current_second = 0;
  11.     int current_amount = 0;
  12.     int current_first;
  13.     for (int i = 0; i < amount; i++) {
  14.         std::cin >> current_first;
  15.         if (!dead_end.empty() && dead_end.back() < current_first) {
  16.             actions.clear();
  17.             break;
  18.         }
  19.         dead_end.push_back(current_first);
  20.         current_amount++;
  21.         if (dead_end.back() == current_second + 1) {
  22.             actions.emplace_back(1, current_amount);
  23.             current_amount = 0;
  24.             while (!dead_end.empty() && dead_end.back() == current_second + 1) {
  25.                 current_amount++;
  26.                 current_second++;
  27.                 dead_end.pop_back();
  28.             }
  29.             actions.emplace_back(2, current_amount);
  30.             current_amount = 0;
  31.         }
  32.     }
  33.     if (actions.empty()) {
  34.         std::cout << 0;
  35.     } else {
  36.         for (const auto& tpl : actions) {
  37.             std::cout << std::get <0>(tpl) << " " << std::get <1>(tpl) << std::endl;
  38.         }
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement