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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);

    for (int i=0; i<n; ++i)
        cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    k--; //przeindeksowanie
    int l = k;

    while (l+1 <= n-1 and a[l+1] == a[k])
        l++;

    cout << l+1;

    return 0;
}