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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdio>

int n, k;
int ranks[2021];
int tmp[2021];

void sort(int begin, int end)
{
	if (end - begin < 2) return;

	int mid = (begin + end) / 2;

	sort(begin, mid);
	sort(mid, end);

	int a = begin;
	int b = mid;
	int c = 0;

	while (a < mid && b < end)
	{
		if (ranks[a] > ranks[b]) tmp[c++] = ranks[a++];
		else tmp[c++] = ranks[b++];
	}

	while (a < mid) tmp[c++] = ranks[a++];
	while (b < end) tmp[c++] = ranks[b++];

	c = 0;
	
	while (begin < end) ranks[begin++] = tmp[c++];
}

int solve()
{
	int min_score = ranks[k - 1];
	int begin = 0;
	int end = n;
	int mid;
	while (begin < end)
	{
		mid = (begin + end) / 2;
		if (ranks[mid] < min_score) end = mid;
		else begin = mid + 1;
	}
	return end;
}

int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) scanf("%d", &ranks[i]);
	sort(0, n);
	int ans = solve();
	printf("%d\n", ans);
	return 0;
}