fork(3) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[100005];
  5. vector<int> v;
  6.  
  7. signed main(){
  8. //clock_t clk = clock();
  9. ios::sync_with_stdio(false);
  10. cin.tie(0);
  11.  
  12. //freopen("inp10.txt", "r", stdin);
  13. //freopen("out10.txt","w",stdout);
  14.  
  15. int n,k;
  16. cin>>n>>k;
  17.  
  18. for(int i = 0; i < n; i++)
  19. cin>>a[i];
  20.  
  21. if(k < n/2){
  22. sort(a,a+n);
  23. for(int i = 0; i < n; i++)
  24. cout<<a[i]<<" ";
  25. return 0;
  26. }
  27.  
  28. for(int i = 0; i < n; i++){
  29. if(i >= n-k-1 && i <= k) continue;
  30. v.push_back(a[i]);
  31. }
  32. sort(v.begin(), v.end());
  33. int j = 0;
  34. for(int i = 0; i < n; i++){
  35. if(i >= n-k-1 && i <= k)
  36. cout<<a[i]<<" ";
  37. else
  38. cout<<v[j++]<<" ";
  39. }
  40. //cout<<endl;
  41. //cerr<<(double)(clock()-clk)/CLOCKS_PER_SEC;
  42. return 0;
  43. }
Success #stdin #stdout 0s 4204KB
stdin
Standard input is empty
stdout
Standard output is empty