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