fork(1) download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int t;
  7. cin >> t;
  8. while (t--)
  9. {
  10. int n, k;
  11. cin >> n >> k;
  12. vector<int> A(n,0);
  13. unordered_map<int, int> mp;
  14. for(int i=0;i<n;i++)
  15. {
  16. cin>>A[i];
  17. mp[A[i]]++;
  18. }
  19. long long ans = 1;
  20. sort(A.begin(),A.end());
  21. vector<int> cost;
  22. for (int i = 0; i < k; i++)
  23. {
  24. cost.push_back(A[i]);
  25. }
  26. int mx = *max_element(cost.begin(),cost.end());
  27. int i = 0;
  28. for (i = 0; i < k; i++)
  29. {
  30. if (A[i] == mx)
  31. {
  32. break;
  33. }
  34. }
  35. while (i < k)
  36. {
  37. ans = ans * mp[mx];
  38. mp[mx]--;
  39. i++;
  40. }
  41. cout << ans << endl;
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5280KB
stdin
2
4 3
4 1 3 2
3 2
2 1 2
stdout
1
2