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. // Count players with strength strictly greater than player j
  22. int stronger_players = 0;
  23. // Also count players with exactly the same strength
  24. int equal_players = 0;
  25.  
  26. for (int i = 0; i < n; i++) {
  27. if (a[i] > player_j_strength) {
  28. stronger_players++;
  29. } else if (a[i] == player_j_strength) {
  30. equal_players++;
  31. }
  32. }
  33.  
  34. // Special case for k=1 (winner): j must have the maximum strength
  35. if (k == 1) {
  36. if (stronger_players == 0) {
  37. cout << "YES\n";
  38. } else {
  39. cout << "NO\n";
  40. }
  41. } else {
  42. // General case: j can survive if there are fewer than k stronger players
  43. if (stronger_players < k) {
  44. cout << "YES\n";
  45. } else {
  46. cout << "NO\n";
  47. }
  48. }
  49. }
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 5328KB
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
NO
YES
NO