fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int t;
  7. cin >> t;
  8.  
  9. while (t--) {
  10. int n, j, k;
  11. cin >> n >> j >> k;
  12.  
  13. vector<int> a(n);
  14. for (int i = 0; i < n; i++) {
  15. cin >> a[i];
  16. }
  17.  
  18. // Player j has 0-indexed position j-1
  19. int player_j_strength = a[j-1];
  20.  
  21. // Different approach: check if player j's strength is among the top k strengths
  22. // Count how many players have strength greater than OR EQUAL to player j
  23. int players_at_least_as_strong = 0;
  24. for (int i = 0; i < n; i++) {
  25. if (a[i] >= player_j_strength) {
  26. players_at_least_as_strong++;
  27. }
  28. }
  29.  
  30. // Player j can be in top k if there are at least k players with strength >= j's strength
  31. // This means j's strength is among the top k strengths
  32. if (players_at_least_as_strong >= k) {
  33. cout << "YES\n";
  34. } else {
  35. cout << "NO\n";
  36. }
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5320KB
stdin
3
5 2 3
3 2 4 4 1
5 4 1
5 3 4 5 2
6 1 1
1 2 3 4 5 6
stdout
YES
YES
YES