#include <iostream>
#include <algorithm>
#include <vector>
int main() {
int n, k;
std::cin >> n >> k;
std::vector<int> points(n);
for (int i = 0; i < n; i++) {
std::cin >> points[i];
}
std::sort(points.begin(), points.end(), [](const int &x, const int &y) { return x > y;});
int idx = k - 1;
while(idx + 1 < n && points[idx + 1] == points[k - 1]) {
++idx;
}
std::cout << idx + 1 << '\n';
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> #include <algorithm> #include <vector> int main() { int n, k; std::cin >> n >> k; std::vector<int> points(n); for (int i = 0; i < n; i++) { std::cin >> points[i]; } std::sort(points.begin(), points.end(), [](const int &x, const int &y) { return x > y;}); int idx = k - 1; while(idx + 1 < n && points[idx + 1] == points[k - 1]) { ++idx; } std::cout << idx + 1 << '\n'; return 0; } |
English