1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    std::ios_base::sync_with_stdio(0);
    size_t n, k;
    std::cin >> n >> k;
    std::vector<int> v(n);
    for (size_t i = 0; i < n; ++i) {
        std::cin >> v[i];
    }
    std::sort(v.rbegin(), v.rend());
    size_t num_extra = 0;
    while (k + num_extra < n && v[k + num_extra - 1] == v[k + num_extra]) {
        ++num_extra;
    }
    std::cout << (k + num_extra) << std::endl;
}