#include <algorithm>
#include <functional>
#include <iostream>
int main()
{
int n, k;
std::cin >> n >> k;
std::vector <int> pkt;
pkt.resize(n);
for (int i = 0; i < n; ++i)
std::cin >> pkt[i];
std::sort(pkt.begin(), pkt.end(), std::greater <int> ());
while (k < n && pkt.at(k) == pkt.at(k - 1))
++k;
std::cout << k << 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 | #include <algorithm> #include <functional> #include <iostream> int main() { int n, k; std::cin >> n >> k; std::vector <int> pkt; pkt.resize(n); for (int i = 0; i < n; ++i) std::cin >> pkt[i]; std::sort(pkt.begin(), pkt.end(), std::greater <int> ()); while (k < n && pkt.at(k) == pkt.at(k - 1)) ++k; std::cout << k << std::endl; return 0; } |
English