I am not getting passed wiht test cases though my logic is correct

#include
#include
#define int long long int
using namespace std;

void unlock(int arr[],int n, int k){
for(int j=1; j<=n && k>0; j++){
if(arr[j-1] < arr[j]){
int idx = max_element(arr+j, arr+n)-arr;
swap(arr[j-1],arr[idx]);
k–;
}
}
return;
}

int32_t main(){
int n,k;
cin>>n>>k;
int arr[n];
for(int i=0; i<n; i++){
cin>>arr[i];
}
unlock(arr,n,k); /// fxn

for(int i=0; i<n; i++)
    cout<<arr[i]<<" ";

return 0;
}

Hello @Mr_Sidd your logic is wrong as the inbuilt stl is disturbing the time complexity.
you shoudl think of some logic for doing this question.
https://ide.codingblocks.com/s/389671(see this for logic ):
and here is the code:
https://ide.codingblocks.com/s/389672
if you have any doubt you can ask here:
Happy Learning!!

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.