Unlock problem stl

Hi I am getting TLE in 4th testcase. Here is my code
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;

int main()
{
#ifndef test
freopen(“input.txt”, “r” , stdin);
freopen(“output.txt”, “w”, stdout);
#endif
ll n, k;
cin >> n;
cin >> k;
ll a[n];
for (ll i = 0 ; i < n ; i++)
cin >> a[i];

for (ll i = 0 ; i < n && k > 0 ; i++)
{
    ll max = *max_element(a + i, a + n);
    if (a[i] != max)
    {
        ll in = find(a + i, a + n, max) - a;
        swap(a[i], a[in]);
        k--;
    }
}

for (ll i = 0 ; i < n ; i++)
    cout << a[i] << " ";

}