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

int solution(std::vector<int>& data, int tshirts) {
    std::sort(data.begin(), data.end(), std::greater<int>{});

    auto last = data.begin() + tshirts - 1;
    auto next = last + 1;

    while(next != data.end() && *last == *next) {
        ++tshirts;
        ++next;
    }

    return tshirts;
}

int main()
{
    std::vector<int> vec;
    int people, tshirts;

    std::cin >> people >> tshirts;
    vec.reserve(people);

    int buff;
    while(people--) {
        std::cin >> buff;
        vec.push_back(buff);
    }

    std::cout << solution(vec, tshirts) << '\n';


    return 0;
}