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

using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k, li = 0;
    cin >> n >> k;
    int tab[n + 9];

tab[0]=1e9;
    for (int i = 1; i <= n; i++)
    {
        cin >> tab[i];
    }
    sort(tab+1, tab + n+1);

    if (tab[n - k+1] != tab[n - k] || k == n)
    {
        cout << k;
    }
    else
    {
        int licz = n - k+1;
        while (tab[licz] == tab[licz - 1])
        {
            li++;
            licz--;
          
        }
        cout << k + li;
    }

    return 0;
}