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 niza[n];
- pair<int, int> p[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- p[i] = make_pair(niza[i], i);
- }
- sort(p, p + n);
- int l = 0, r = n - 1;
- for(int i = 0; i < k; i++) {
- swap(niza[p[l].second], niza[p[r].second]);
- l++;
- r--;
- }
- for(int i = 0; i < n; i++) {
- cout << niza[i] << " ";
- }
- return 0;
- }
- /*
- (50, 0) (100, 1) (45, 2) (2000, 3) (1300, 4)
- 50 100 45 2000 1300
- к = 1
- (45, 2) (50, 0) (100, 1) (1300, 4) (2000, 3)
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement