Runtime error with 4.51 secs in Unlock question what is wrong in my code

#include
using namespace std;
int maximum(long long int j, long long int arr[], long long int n)
{
long long int i, indx =j, max = arr[j];
for(i=j+1;i<n;i++)
{
if(arr[i] > max)
{
max = arr[i];
indx = i;
}
}
return indx;
}

void swap(long long int a, long long int b)
{
long long int tmp;
tmp = a;
a=b;
b= tmp;
}
int main() {

long long int n,k,i,j=0,tmp;
cin>>n>>k;
long long int arr[n];
for(i=0;i<n;i++)
    cin>>arr[i];

for(i=0;i<k;i++)
{
    long long int q = maximum(j,arr,n);
     if(q==j)
        k++;

        tmp = arr[j];
        arr[j]  = arr[q];
        arr[q] = tmp;
        j++;
        
   
}


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

}

Don’t paste raw code. Please send your code link.

See contraints , K can be upto 1e9. You can’t iterate for 1e9.
Working code -:

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.