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

int main() {
    int n, k;
    std::cin >> n >> k;
    std::vector <int> results(n, 0);
    std::for_each(results.begin(), results.end(), [](int &i) {
        std::cin >> i;
    });
    std::sort(results.begin(), results.end(), std::greater<int>());
    std::cout << (k - 1) + std::count(std::next(results.begin(), k - 1), results.end(), results[k - 1]);
}