#include <iostream> #include <vector> #include <algorithm> int main() { int n, k; std::cin >> n >> k; std::vector<int> part; for (int i = 0; i < n; i++) { int tmp; std::cin >> tmp; part.push_back(tmp); } std::sort(part.begin(), part.end(), [](int a, int b) {return a > b; }); size_t size = part.size() - 1; for (int i = k - 1; i < size; i++) { if (part.at(i + 1) == part.at(i)) k++; else break; } std::cout << k; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <vector> #include <algorithm> int main() { int n, k; std::cin >> n >> k; std::vector<int> part; for (int i = 0; i < n; i++) { int tmp; std::cin >> tmp; part.push_back(tmp); } std::sort(part.begin(), part.end(), [](int a, int b) {return a > b; }); size_t size = part.size() - 1; for (int i = k - 1; i < size; i++) { if (part.at(i + 1) == part.at(i)) k++; else break; } std::cout << k; } |