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

using namespace std;

int main() {
    int n, k;
    int arr[2000];
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    sort(arr, arr + n);
    int x = n - k;
    int out = k;
    while (x > 0 && arr[x - 1] == arr[x]){
        x--;
        out++;
    }
    cout << out;
    return 0;
}