fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. int t, n, k, s;
  8. cin >> t;
  9. for(int p=0; p < t; p++){
  10. cin >> n >> k;
  11.  
  12. vector<int> scores;
  13. for(int i=0; i < n; i++){
  14. cin >> s;
  15. scores.push_back(s);
  16. }
  17.  
  18. sort(scores.begin(), scores.end());
  19. reverse(scores.begin(), scores.end());
  20.  
  21. int count = 1, rank = 1;
  22. if(n > 1){
  23. for(int j=1; j < n; j++){
  24. if(scores[j] < scores[j-1]){
  25. rank++;
  26. if(rank <= k){
  27. count++;
  28. }
  29. } else {
  30. if(rank <= k){
  31. count++;
  32. }
  33. }
  34. }
  35. cout << count << endl;
  36. } else {
  37. cout << 1;
  38. }
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 15240KB
stdin
1
10 2
1 9 6 3 6 6 2 9 2 3
stdout
5