Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<algorithm>
- using namespace std;
- int main()
- {
- int n,k;
- cin>>n>>k;
- int a[n];
- int m;
- pair<int,int>p[n];
- for(int i=0;i<n;i++)
- {
- cin>>p[i].first;
- p[i].second=i;
- a[i]=p[i].first;
- }
- sort(p,p+n);
- for(int i=0;i<k;i++)
- {
- m=a[p[i].second];
- a[p[i].second]=a[p[n-i-1].second];
- a[p[n-i-1].second]=m;
- }
- for(int i=0;i<n;i++)
- {
- cout<<a[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement