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
#include <bits/stdc++.h>
using namespace std;

typedef long long int LL;

int n, k, a, sum;
map<int, int> counts;

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
    {
        cin >> a;
        ++counts[a];
    }

    for(auto it = counts.rbegin(); it != counts.rend(); ++it)
    {
        sum += it->second;

        if(sum >= k)
        {
            cout << sum << endl;
            return 0;
        }
    }

    return 0;
}