fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, x;
  7. cin >> n >> x;
  8.  
  9. int a[100005];
  10.  
  11. for (int i = 0; i < n; i++)
  12. cin >> a[i];
  13.  
  14. int pos = n;
  15. for (int i = 0; i < n; i++) {
  16. if (a[i] >= x) {
  17. pos = i;
  18. break;
  19. }
  20. }
  21.  
  22. for (int i = n; i > pos; i--)
  23. a[i] = a[i - 1];
  24.  
  25. a[pos] = x;
  26. n++;
  27.  
  28. for (int i = 0; i < n; i++)
  29. cout << a[i] << " ";
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
0