#include <bits/stdc++.h>
int32_t main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
int n, k;
std::cin >> n >> k;
std::vector <int> a(n);
for (auto &i : a) std::cin >> i;
std::sort(a.begin(), a.end(), std::greater<int>());
int result = k;
int i = k;
while (i < n && a[i] == a[k - 1]) ++i, ++result;
std::cout << result << '\n';
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <bits/stdc++.h> int32_t main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int n, k; std::cin >> n >> k; std::vector <int> a(n); for (auto &i : a) std::cin >> i; std::sort(a.begin(), a.end(), std::greater<int>()); int result = k; int i = k; while (i < n && a[i] == a[k - 1]) ++i, ++result; std::cout << result << '\n'; return 0; } |
English