Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <tuple>
- int main() {
- int amount;
- std::cin >> amount;
- std::vector<int> dead_end;
- std::vector<std::tuple<int, int>> actions;
- int current_second = 0;
- int current_amount = 0;
- int current_first;
- for (int i = 0; i < amount; i++) {
- std::cin >> current_first;
- if (!dead_end.empty() && dead_end.back() < current_first) {
- actions.clear();
- break;
- }
- dead_end.push_back(current_first);
- current_amount++;
- if (dead_end.back() == current_second + 1) {
- actions.emplace_back(1, current_amount);
- current_amount = 0;
- while (!dead_end.empty() && dead_end.back() == current_second + 1) {
- current_amount++;
- current_second++;
- dead_end.pop_back();
- }
- actions.emplace_back(2, current_amount);
- current_amount = 0;
- }
- }
- if (actions.empty()) {
- std::cout << 0;
- } else {
- for (const auto& tpl : actions) {
- std::cout << std::get <0>(tpl) << " " << std::get <1>(tpl) << std::endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement