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
39
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;


int main()
{
	/* Loading inputs */
	int n;
	int k;
	vector<int> v;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		int value = 0;
		scanf("%d", &value);
		v.push_back(value);
	}
	
	/* Solution */
	if (n == k) {
		printf("%d\n", n);
	} else {
		sort(v.begin(), v.end(), greater<int>());
		int result = k;
		for (int i = k; i < n; ++i) {
			if (v[i] == v[i-1]) {
				result++;
			} else {
				break;
			}
		}
		printf("%d\n", result);
	}

}