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 <cstdio>
#include <cstdlib>
#include <cassert>

#include <algorithm>

int nums[2000];

int main() {
    int n, k;
    assert(2 == scanf("%d %d\n", &n, &k));

    for (int i = 0; i < n; i++) {
        assert(1 == scanf("%d", &nums[i]));
    }

    std::sort(nums, nums + n);
    
    const int worst = nums[n - k];
    while (k < n && nums[n - (k + 1)] == worst) {
        k++;
    }

    printf("%d\n", k);

    return 0;
}