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

const int MAX_N = 2e3 + 5;

int a[MAX_N];

int main() {

    cin.tie(0); ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    sort(a+1, a+n+1, greater<int>());

    int last_index = k;
    while(a[last_index+1] == a[k]) last_index++;

    cout << last_index;
    
}