Răspuns:
#include <iostream>
using namespace std;
int main(){
int n, m, foi[1300001], i;
cin >> n;
cin >> m;
for(i = 0; i < n; i++) {
cin >> foi[i];
}
int op, numar, max_length = n, min_length = 0;
for(i = 0; i < m; i++) {
cin >> op;
if(op == 2) {
cin >> numar;
foi[max_length] = numar;
max_length++;
}else if (op == 1) {
if (min_length < max_length) {
min_length++;
}
}
}
cout << max_length-min_length;
cout << endl;
for(i = min_length; i < max_length; i++) {
cout << foi[i] << " ";
}
return 0;
}
Explicație: