What is wrong with folllowing code?

#include
#include
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int k;
cin>>n>>k;

int a[100];
int x=1;
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
for(int i=0;i<n;i++)
{
	
auto it=max_element(a+i,a+n);
int index=it-a;
if(a[index>a[i]] && x<=k)
{
swap(a[index],a[i]);
x++;
}
}
for(int i=0;i<n;i++)
{
	cout<<a[i]<<"";
}
return 0;
}

Please run your code on https://ide.codingblocks.com/ and share the link

@mayank10 I corrected your code https://ide.codingblocks.com/s/201380 , you can see the changes here.
But your approach results in TLE , try to think of a way you can do this question by hashing because finding max element every time will result in time out.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.