Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- unsigned n, p, c;
- vector<unsigned> b;
- vector<string> answer;
- cin >> n;
- p = 1;
- for (unsigned i = 0; i < n; ++i) {
- cin >> c;
- answer.push_back("push");
- if (c == p) {
- answer.push_back("pop");
- ++p;
- } else {
- b.push_back(c);
- }
- while (b.size() > 0 && *b.rbegin() == p) {
- b.pop_back();
- answer.push_back("pop");
- ++p;
- }
- }
- if (p != n + 1) {
- cout << "impossible" << endl;
- } else {
- for (string action: answer) {
- cout << action << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement