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
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;

	vector<int> nums(n);
	for (int i=0; i<n; i++) {
		cin >> nums[i];
	}
	sort(nums.begin(), nums.end());

	// for (auto x: nums) cout << x << " ";
	// cout << "\n";

	int cnt = 0;
	int add = 0;
	for (int i=n-1; i>=0; i--) {
		if (cnt == k) {
			while (nums[i+1] == nums[i]) {
				add++;
				i--;
			}
			break;
		} else {
			cnt++;
		}
	}
	cout << cnt + add << "\n";
}

int main() {solve();}