1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>

using namespace std;

int main()
{
    cin.tie(nullptr)->sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &i : a)
        cin >> i;
    sort(a.rbegin(), a.rend());
    for (int i = k; i < n; i++)
        if (a[i] == a[i - 1])
            k++;
        else
            break;
    cout << k << '\n';
}