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
#include "bits/stdc++.h"

using namespace std;

vector <int> p;
int l[127]={0};

bool porownaj(const int &a, const int &b)
{
    return (a > b);
}

int main() {

    int n, k, a;
    int r = 0;
    int c = 0;
    int j;

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    cin >> k;

    p.reserve(n+7);

    for (int i = 0; i < n; i++)
    {
        cin >> a;
        p.push_back(a);
        l[a]++;
    }

    sort(p.begin(), p.end(), porownaj);

    for (int i = 0; i < k; i++)
    {
        j = i;
        if (r != p[i])
        {
            c = 0;
            r = p[i];
        }

        c++;
    }

    cout << k + l[p[j]]-c;

    exit(0);
}