#include <algorithm> #include <iostream> int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; std::cin >> n >> k; int a[n + 1]; a[0] = -1; for (int i = 1; i <= n; i++) { std::cin >> a[i]; } std::sort(a, a + n + 1); int i = n + 1 - k; while (a[i-1] == a[i]) { i--; } int result = n - (i - 1); std::cout << result << std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <algorithm> #include <iostream> int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; std::cin >> n >> k; int a[n + 1]; a[0] = -1; for (int i = 1; i <= n; i++) { std::cin >> a[i]; } std::sort(a, a + n + 1); int i = n + 1 - k; while (a[i-1] == a[i]) { i--; } int result = n - (i - 1); std::cout << result << std::endl; return 0; } |