Advertisement
Josif_tepe

Untitled

Feb 26th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n,k;
  8.     cin>>n>>k;
  9.     int a[n];
  10.     int m;
  11.     pair<int,int>p[n];
  12.     for(int i=0;i<n;i++)
  13.     {
  14.         cin>>p[i].first;
  15.         p[i].second=i;
  16.         a[i]=p[i].first;
  17.     }
  18.     sort(p,p+n);
  19.     for(int i=0;i<k;i++)
  20.     {
  21.         m=a[p[i].second];
  22.         a[p[i].second]=a[p[n-i-1].second];
  23.         a[p[n-i-1].second]=m;
  24.     }
  25.     for(int i=0;i<n;i++)
  26.     {
  27.         cout<<a[i]<<" ";
  28.     }
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement