This code is giving runtime error but it is running successfully on other compilers what is it's runtime error

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,a[n],k;
cin>>t;
for(int j =1;j<=t;j++)
{ int count=0;
cin>>n>>k;
int m=sizeof(a)/sizeof(a[0]);
for(int j=0;j<n;j++)
{
cin>>a[j];

     }
     sort(a, a+n, greater<int>());
    for(int j=0;j<n;j++)
    {
       if(a[j]>=a[k-1])
            count+=1;

    }
   cout<<count;
}
return 0;

}

Look carefully at the constraints. For example, what happens in your program if k > n? What happens if n=0? (in this case you get a division by 0 exception) Etc.