Advertisement
Josif_tepe

Untitled

Mar 7th, 2024
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. //#include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main() {
  9.     ios_base::sync_with_stdio(false);
  10.     int n, k;
  11.     cin >> n >> k;
  12.     int niza[n];
  13.     vector<pair<int, int>> v;
  14.     for(int i = 0; i < n; i++) {
  15.         cin >> niza[i];
  16.         v.push_back(make_pair(niza[i], i));
  17.     }
  18.     sort(v.begin(), v.end());
  19.     for(int i = 0; i < k; i++) {
  20.         swap(niza[v[i].second], niza[v[n - i - 1].second]);
  21.     }
  22.     for(int i = 0; i < n; i++) {
  23.         cout << niza[i] << " ";
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement