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
28
29
30
31
32
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    ll n, k, res = 0, a;
    cin >> n >> k;
    vector<ll> numbers;

    for (ll i = n; i > 0; --i) {
        cin >> a;
        numbers.push_back(a);
    }

    sort(numbers.begin(), numbers.end(), greater<ll>());

    for (ll i = 0; i < numbers.size(); ++i) {
        if (k > 0 or numbers[i] == numbers[i - 1]) {
            res++;
            k--;
        } else {
            break;
        }
    }

    cout << res << endl;
    return 0;
}