HTML & JS
#include <bits/stdc++.h>

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll> 
#define ff first
#define ss second
#define PB push_back
#define F(i,L,R) for(auto i=L; i<R ;i++)
#define FR(i,R,L) for(auto i=R;i>L;i--)
#define all(x) (x).begin(),(x).end()
#define show(x) cout<<(#x)<<" = "<<(x)<<"\n";
#define show2(x,y) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<"\n";
#define show3(x,y,z) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<" & "<<(#z)<<" = "<<(z)<<"\n";
#define endln "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define M 1000000007
//#define INT_MAX 2147483647
#define int ll

using namespace std;

// int nck(int n,int k)
// {
//     if(n==0) return 0;    
//     if(k==0) return 1;
    
//     int ans=1;
//     for(int i=0;i<k;i++)
//     {
//         ans*=n-i;
//         ans/=(i+1);
//     }

//     return ans;
// }
#include <bits/stdc++.h>
using namespace std;
 
int power(int a, int b){
    a%=M;
    if(a==0)
        return 0;
    int ans = 1;
    while(b>0){
        if(b&1)
            ans=(ans * a%M)%M;
        b>>=1;
        a = (a*a)%M;
    }
    return ans%M;
}

int MMI(int n){
    return power(n,M-2);
}

int nck(int n,int k)
{
    if(k==0)
        return 1;
    int ans = 1;

    for(int i=0;i<k;i++)
    {
        ans = (ans * (n-i)%M)%M;
        ans = (ans%M * MMI(i+1))%M;
    }
    return ans%M;
}

signed main() 
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
	#endif // ONLINE_JUDGE

	fastio;
	int test;
	cin>>test;
	while(test--)
	{
        int n,k;
        cin>>n>>k;

        vi arr(n);
        for(int i=0;i<n;i++)
            cin>>arr[i];

        sort(arr.begin(),arr.end(),greater<int>());

        int tofind = arr[k-1];
        int nonfind = 0;
        int cnt=0;
        bool found = false;
        for(int i=0;i<n;i++)
        {
            if(arr[i]==tofind && found==false){
                found=true;
                nonfind=i;
            }

            if(arr[i]==tofind)
                cnt++;
        }

        int toselect = k - nonfind;
//        cout<<cnt<<" "<<toselect<<" ";
        cout<<nck(cnt, toselect)<<"\n";

	}

}



Generated URL:

Output:

No Output
Report Bug