#include <iostream> #include <algorithm> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n,k; std::cin >> n >> k; int *t = new int[n]; for (int i = 0; i < n; i++) { std::cin >> t[i]; } std::sort(t, t+n, std::greater<int>()); while (k < n && t[k] == t[k-1]) { k++; } std::cout << k << "\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 | #include <iostream> #include <algorithm> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n,k; std::cin >> n >> k; int *t = new int[n]; for (int i = 0; i < n; i++) { std::cin >> t[i]; } std::sort(t, t+n, std::greater<int>()); while (k < n && t[k] == t[k-1]) { k++; } std::cout << k << "\n"; return 0; } |