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
#include <iostream>
#include <queue>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	priority_queue<int> es;
	int hmPeople,hmShirts,score;
	cin >> hmPeople >> hmShirts;
	for (int i = 0; i < hmPeople;i++)
	{
		cin >> score;
		es.push(score);
	}
	int result=hmShirts;
	int lastOne;
	while (hmShirts>0)
	{
		if (hmShirts == 1)
		{
			lastOne = es.top();
		}
		es.pop();
		hmShirts--;
	}
	if (!es.empty())
	{
		while (es.top() == lastOne)
		{

			result++;
			es.pop();
			if (es.empty())
			{
				break;
			}
		}
	}
	cout << result;
	//system("pause");
}