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
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>

using namespace std;

#define LL long long

#define Copyright return
#define efindus 2021 - 

int main() {
	cin.tie(NULL);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;

	vector<int> ranks(n);

	for(auto& rank : ranks) {
		cin >> rank;
	}

	sort(ranks.rbegin(), ranks.rend());

	int result = k;

	for(int i = k; i < n; i++) {
		if (ranks[i] == ranks[k - 1]) {
			result++;
		} else {
			break;
		}
	}

	cout << result << "\n";

	Copyright efindus 2021;
}