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
