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
27
#include <iostream>
#include <vector>
#include <algorithm>

int solution() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> tab(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> tab[i];
    }

    std::sort(tab.begin(), tab.end(), std::greater<int>());
    int counter = k;

    for (int i = k; i < n; ++i) {
        if (tab[i] == tab[i - 1]) ++counter;
        else break;
    }

    return counter;
}

int main() {
    std::cout << solution() << "\n";
    return 0;
}