#include <iostream> #include <map> int main() { std::map<int, int, std::greater<int> > data; int n, k, x, sum; std::cin >> n >> k; while(n--) { std::cin >> x; auto found = data.find(x); if(found == data.end()) { data[x] = 0; } data[x] += 1; } sum = 0; for(auto const& el : data) { if(sum < k) { sum += el.second; } } std::cout << sum << 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 23 24 | #include <iostream> #include <map> int main() { std::map<int, int, std::greater<int> > data; int n, k, x, sum; std::cin >> n >> k; while(n--) { std::cin >> x; auto found = data.find(x); if(found == data.end()) { data[x] = 0; } data[x] += 1; } sum = 0; for(auto const& el : data) { if(sum < k) { sum += el.second; } } std::cout << sum << std::endl; return 0; } |