Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- int main()
- {
- _test
- {
- int n, k;
- cin>>n>>k;
- vector<int> a(n);
- for(auto &e: a)
- cin>>e;
- if(k >= n)
- {
- for(auto e: a)
- cout<<e<<" ";
- cout<<"\n";
- }
- else
- {
- vector<int> v;
- for(int i=0; i<n; i++)
- {
- if(i<k && (n-1-i)<k) continue;
- v.pb(a[i]);
- }
- sort(v.begin(), v.end());
- for(int i=0, j=0; i<n; i++)
- {
- if(i<k && (n-1-i)<k) continue;
- a[i] = v[j++];
- }
- for(auto e: a)
- cout<<e<<" ";
- cout<<"\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment