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

constexpr int MAX_A = 2007;

int n,k;
int res = 0;
int a[MAX_A];

int main() {
    cin >> n >> k;
    if ( k >= n ) {
        cout << n << "\n";
        return 0;
    }
    for ( int i = 0; i<n; i++ ) cin >> a[i];
    sort(a, a+n, greater<int>());
    for ( int i = k; i<n; i++ ) {
        if ( a[i] == a[k-1] )
            res++;
    } 
    cout << res+k << "\n";
}