60分求助(前3个AC,后2个TLE)

P1923 【深基9.例4】求第 k 小的数

Algorithm_ZRF @ 2023-07-31 11:44:12

#include <bits/stdc++.h>
using namespace std;
int n, k, a;
priority_queue<int, vector<int>, greater<int>> q;
inline void Judgment() {
    for (int i = 0; i < n; ++i) {
        if (i == k) {
            cout << q.top();
            break;
        }
        q.pop();
    }
}
inline void Read() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        q.push(a);
    }
    Judgment();
}

int main() {
    Read();
    return 0;
}

|