#include <iostream> #include <vector> #include <algorithm> int main() { std::ios::sync_with_stdio(false); int k, n; std::cin >> n >> k; std::vector<int> v(n); for (int i = 0 ; i < n ; ++i) { std::cin >> v[i]; } std::sort(v.begin(), v.end()); int last = -1; int res = 0; for (int i = n - 1; i >= 0; --i) { if (last != v[i] and (n - 1 - i) >= k) { std::cout << n - 1 - i; return 0; } last = v[i]; } std::cout << 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 26 | #include <iostream> #include <vector> #include <algorithm> int main() { std::ios::sync_with_stdio(false); int k, n; std::cin >> n >> k; std::vector<int> v(n); for (int i = 0 ; i < n ; ++i) { std::cin >> v[i]; } std::sort(v.begin(), v.end()); int last = -1; int res = 0; for (int i = n - 1; i >= 0; --i) { if (last != v[i] and (n - 1 - i) >= k) { std::cout << n - 1 - i; return 0; } last = v[i]; } std::cout << n; return 0; } |