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 main() {
    ios_base::sync_with_stdio(NULL);
    
    int n, k;
    cin>>n>>k;
    
    int a[n];
    for (int i=0; i<n; ++i) cin>>a[i];
    sort(a, a+n, greater<int>());
    
    int minv = INT_MAX, ans=0;
    for (int i=0; i<min(k, n); ++i) {
        ++ans;
        minv = min(minv, a[i]);
    }
    
    for (int i=k; i<n; ++i) {
        if (a[i] == minv) ++ans;
        else break;
    }
    
    cout<<ans<<endl;
}