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
/*
 * kos.cpp
 *
 *  Created on: Dec 7, 2021
 *      Author: A.Mulawa
 */

#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <bits/stdc++.h>

int main(int argc, char **argv)
{
    int n, k;
    scanf("%d %d", &n, &k);
    int p[2001];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
    }
    std::sort(p, p + n);
    int kk = 0;
    int klast = INT_MAX;
    for (int i = n - 1; i >= 0; i--)
    {
        if (kk < k)
        {
            kk++;
            klast = p[i];
        }
        else if (p[i] >= klast)
        {
            kk++;
        }
    }
    printf("%d", kk);
};