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<bits/stdc++.h>

using namespace std;

int n,k,a;

int main(){
    cin >> n >> k;
    vector<int> V;
    for (int i = 1; i <= n; i++){
        cin >> a;
        V.push_back(a);
    }
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    int last = V[0];
    int ans = 0;
    for (auto i : V){
        if(ans < k || i == last)
            ans++;
        else
            break;
        if(i != last)
            last = i;
    }
    cout << ans << endl;
}