#include
#include
#include <unordered_map>
using namespace std;
int main() {
int n,k,arr[100000],i,hold;
cin>>n>>k;
unordered_map<int,int> m1;
for(i=0;i<n;i++){
cin>>arr[i];
m1.insert(make_pair(arr[i],i));
}
int num=n;
int m=0;
while(m<n && k>0) {
auto f= m1.find(num-m);
if(f!=m1.end()){
hold=f->second;
if(hold==n-num+m) { // Check if the number is present at the best spot
m++;
continue;
} else { // If the number is not present at the best spot then swap the number with the element at that spot
swap(arr[hold],arr[m]);
m1.insert(make_pair(arr[hold], hold));
m1.insert(make_pair(arr[m],m));
m++;
k--;
}}}
for (auto i = m1.begin(); i != m1.end(); i++)
cout << i->first << " ";
return 0;
}
this is my answer in c++ .please guide me to right answer