Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- //#include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int n, k;
- cin >> n >> k;
- int niza[n];
- vector<pair<int, int>> v;
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- v.push_back(make_pair(niza[i], i));
- }
- sort(v.begin(), v.end());
- for(int i = 0; i < k; i++) {
- swap(niza[v[i].second], niza[v[n - i - 1].second]);
- }
- for(int i = 0; i < n; i++) {
- cout << niza[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement