题解
2023-08-21 10:38:27
发布于:广东
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int f(int n, int k, vector<int>& numbers) {
set<int> un(numbers.begin(), numbers.end());
vector<int> sun(un.begin(), un.end());
if (k > sun.size()) {
return -1;
}
sort(sun.begin(), sun.end());
return sun[k - 1];
}
int main() {
int n, k;
cin >> n >> k;
vector<int> numbers(n);
for (int i = 0; i < n; ++i) {
cin >> numbers[i];
}
int result = f(n, k, numbers);
if (result == -1) {
cout << "NO RESULT" << endl;
} else {
cout << result << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个