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

using namespace std;

int main()
{
    int n, k;
    cin >> n;
    cin >> k;
    vector<int> A(n);
    for(int i=0; i<n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    int j=n-k-1;
    int x=k;
    while(j>=0&&A[j]==A[n-k]){
        x++;
        j--;
    }
    
    cout << x;

    return 0;
}