1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int T[2004];
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;
    if (k>n) k=n;
    for (int i=0;i<n;i++) cin >> T[i];
    if (k!=n && k != 0)
    {
        std::sort(T,T+n,std::greater());
        int val = T[k-1];
        while (k<n && T[k] == val) k++;
    }
    cout << k << '\n';
}