Are there any weird corner cases? Or my code is wrong?

I have been testing my program for 30 mins now, and I cannot find a single case where it shows me wrong output.
Can anyone please tell me what is wrong in my program?
The problem is from the STL Challenges named - Unlock
and here is my code

	Author - Arten
*/

#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
	IOS;
	int n, k;
	map<int, int> permut, permut2;
	cin >> n >> k;
	int arr[n];
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		permut[i] = x;
		permut2[x] = i;
	}
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}
	int nc = n;
	for(auto x: permut){
		if(k == 0)
			break;
		if(x.second != n){
			int xy = x.second;
			permut[x.first] = n;
			int xy1 = permut2[n];
			permut[xy1] = xy;
			k--;
			permut2[n] = x.first;
			permut2[xy] = xy1;
		}
		n--;
	}
	if(k != 0){
		if(k % 2 != 0){
			int temp = permut[nc-1];
			permut[nc-1] = permut[nc-2];
			permut[nc-2] = temp;
		}
	}
	for(auto x:permut)
		cout << x.second << " ";	
	cout << endl;




	return 0;
}

Thank you
Akhand

Hi

Please check this code:

#include
#include
using namespace std;

int main(){
int n,i;
cin>>n>>i;
int arr[n],arr2[n+1];
for(int j=0;j<n;j++)
cin>>arr[j];
for(int j=0;j<n;j++){
arr2[arr[j]]=j;
}

for(int j=0;j<n;j++){
    
    ///cout<<arr[0]<<" "<<j<<"\n";
    if(i==0)
    break;
	if(arr[j]==n-j)
	  continue;
	else{
		int temp=arr2[n-j];
		swap(arr[temp],arr[j]);
		arr2[arr[temp]]=temp;
		
		i--;
	}
	
}
for(int j=0;j<n;j++)
cout<<arr[j]<<" ";

}