主要是要考虑重复分数的情况,主要思路:排序后,依次遍历各个分数

#include <algorithm>
#include <vector>
  
 using namespace std;

void scoreBoundry() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> scores(n);
    for (int i = 0; i < n; i++) {
        cin >> scores[i];
    }

    if (x > y || 2 * x > n || 2 * y < n) {
        cout << -1 << endl;
        exit(0);
    }

    sort(scores.begin(), scores.end());
    int i = 0;  
  // 前i个未通过,剩下未n-i个通过, i既代表前i个元素,也代表前i个元素的下一个索引位置        
    while (i < n) { 
   // 二分查找到scores[i]的起始索引范围[i, next), next为下个元素即scores[i+1]的起点位置
        int next = upper_bound(scores.begin() + i, scores.end(), scores[i])  - scores.begin();
        
        if (x <= next && next <= y && x <= n - next && n - next <= y) {     // 首次满足条件,输出最小的m值,并结束
            cout << scores[i]  << endl;
            exit(0);
        }

        if (next > y || n - next < x) {       // i往后遍历,再也不会得到结果,结束
            cout << -1 << endl;
            exit(0);
        }
        i = next;
    }
    cout << -1 << endl;        
}

int main() {

    scoreBoundry();

    return 0;
}