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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string_view>
#include <map>

struct input_t
{
        int32_t num_scores;
        int32_t num_shirts;
        std::map<uint32_t, uint32_t, std::greater<uint32_t>> scores;
        input_t()
                : num_scores()
                , num_shirts()
                , scores()
        {}

        friend std::ostream& operator<<(std::ostream& out, input_t const & in)
        {
                out << "a\n";
                out << "sc:" << in.num_scores;
                out << " sh:" << in.num_shirts<<"\n";
                //return out;
                for(auto const& p: in.scores)
                {
                        out << "[" << p.first << ", " << p.second << "]\n";
                }
                return out;
        }

};

input_t read_input(std::istream& input, std::string& r_str)
{
        input_t in{};
        input >> in.num_scores;
        input >> in.num_shirts;
        for(uint32_t i = 0; i < in.num_scores; ++i)
        {
                uint32_t score =0;
                input >> score;
                auto it = in.scores.find(score);
                if (it != in.scores.end())
                {
                        it->second += 1;
                }
                else
                {
                        in.scores.emplace(std::pair<uint32_t,uint32_t>(score, 1));
                }
        }

        return std::move(in);
}

uint32_t solution(std::istream& input, std::ostream& out)
{
        std::string str;
        auto in = read_input(input, str);
        uint32_t result = 0;
        for(auto const p : in.scores)
        {
                result += p.second;
                in.num_shirts -= p.second;
                if (in.num_shirts <= 0)
                {
                        break;
                }

        }
        out << result << std::endl;
        return result;
}

#ifndef TEST
int main(int argc, char* argv[])
{
        solution(std::cin, std::cout);
        return 0;
}
#endif