fork download
  1. //https://l...content-available-to-author-only...e.ro/submission/1595800
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 9;
  6.  
  7. int main() {
  8. int n, m, v[MAX_SIZE + 1], x;
  9. cin >> n >> m;
  10. for (int i = 1; i <= n; ++i) {
  11. cin >> v[i];
  12. }
  13. for (int j = 1; j <= m; ++j) {
  14. int k;
  15. cin >> k;
  16. if (k == 1) {
  17. if (n > 0) {
  18. --n;
  19. for (int i = 1; i <= n; ++i) {
  20. v[i] = v[i + 1];
  21. }
  22. }
  23. } else if (k == 2) {
  24. if (n < MAX_SIZE) {
  25. cin >> x;
  26. ++n;
  27. v[n] = x;
  28. }
  29. }
  30. }
  31. cout << n << "\n";
  32. for (int i = 1; i <= n; ++i) {
  33. cout << v[i] << " ";
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 5292KB
stdin
4 7
30 21 -81 26
2 6
2 95
2 86
2 -365
2 0
1 
1 - >8
21 -81 26 6 95 86 -365 0

4 8
30 21 -81 26
2 6
2 95
2 86
2 -365
2 0
2 900
1 
1 - >8
21 -81 26 6 95 86 -365 0 am setat constanta = 9, ca sa pot testa nr maxim de elemente, La acest test imi dau seama ca se acceseaza gresit valoarea maxima a lui n, cred 

4 7
30 21 -81 26
2 6
2 95
2 86
2 -365
2 0
2 900
1 - >9
30 21 -81 26 6 95 86 -365 0 am setat constanta = 9, ca sa pot testa nr maxim de elemente 

4 6
30 21 -81 26
2 6
2 95
2 86
2 -365
2 0
2 900 - >9
30 21 -81 26 6 95 86 -365 0 am setat constanta = 9, ca sa pot testa nr maxim de elemente 

1 2
5
1
2 9-> 1
9 

9 9
30 21 -81 26 95 86 -365 0 900 
2 30 
2 21 
1
1
2 -99 
1
2 88 
2 77 
2 55 ->12
26 95 86 -365 0 900 30 21 -99 88 77 55


9 9
30 21 -81 26 95 86 -365 0 900 
2 30 
2 21 
2 -81 
2 26 
2 95 
2 86 
2 -365 
2 0 
2 900 ->18
30 21 -81 26 95 86 -365 0 900 30 21 -81 26 95 86 -365 0 900 

4 5
30 21 -81 26
2 95
2 86
2 -365
2 0
2 900 - >9
30 21 -81 26 95 86 -365 0 900 

4 4
30 21 -81 26
1
1
1
1->0

4 4
30 21 81 26
1
1
1
1->0

4 3
30 21 81 26
1
1
1->1
26

4 3
30 21 81 26
2 68
2 64
1->5
21 81 26 68 64 
stdout
7
-81 26 6 95 86 -365 0