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 a[2001];

int main() {
    int n;
    scanf("%d", &n);
    int k;
    scanf("%d", &k);

    int count=0;
    for (int i = 0; i < n; i++) scanf("%d", a+i);
    sort(a,a+n);
    reverse(a,a+n);
    while(k+count < n && a[k+count]==a[k-1]) count++;
    printf("%d\n",k+count);
    return 0;
}