fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 10000;
  5.  
  6. int main() {
  7. int n, m, v[MAX_SIZE], k, x, t;
  8. cin >> n;
  9. t = n;
  10. for (int i = 1; i <= t; ++i) {
  11. cin >> v[i];
  12. }
  13. cin >> m;
  14. while(m--) {
  15. cin >> k;
  16. if(k == 1) {
  17. cin >> x;
  18. ++t;
  19. v[t] = x;
  20. } else {
  21. --t;
  22. }
  23. }
  24. cout << t << "\n ";
  25. for (int i = 1; i <= t; ++i) {
  26. cout << v[i] <<" ";
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5280KB
stdin
3
5 -4  7 
4
2
2
2
1 9
stdout
1
 9