P1923 【深基9.例4】求第 k 小的数
以上题我提交代码上去,总是会显示TLE,以下是我的代码:
#include<bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
int m, a[n];
for(int i = 0; i < n; i++)
{
cin >> m;
q.push(m);
}
int i = 0;
while(!q.empty())
{
a[i] = q.top();
q.pop();
i++;
}
cout << a[k];
return 0;
}
请各位高人指点,谢谢
附图:
提交结果: