1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <algorithm>
#include <functional>
typedef unsigned int ui;
size_t n, k;
ui *arr;
int main(void) {
	scanf("%lu %lu", &n, &k);
	arr = new ui[n];
	for (size_t i=0; i<n; ++i)
		scanf("%u", &arr[i]);
	std::sort(arr, arr+n, std::greater<ui>());
	// for (size_t i=0; i<n; ++i)
	// 	printf("%u ", arr[i]);
	// puts("");
	ui last=arr[k-1];
	size_t result=k;
	for (size_t i=k; i<n && arr[i]==last; ++i)
		++result;
	printf("%lu\n", result);
	return 0;
}