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
/*
 * =====================================================================================
 *
 *       Filename:  kos.cpp
 *
 *    Description:  
 *
 *        Version:  0.1.0
 *        Created:  07.12.2021
 *
 *         Author:  Michał Zagórski (zagura), <zagura6@gmail.com>
 *
 * =====================================================================================
 */
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
int main() {

    int shirts = 0;
    int count = 0;
    scanf("%d %d", &count, &shirts);
    std::vector<int> results (count);
    for (size_t i = 0; i < count; i++) {
        scanf("%d", &results[i]);
    }
    std::sort(results.begin(), results.end());
    ssize_t index = results.size() - shirts;
    int value, total_count;
    value = results[index];
    
    total_count = shirts - 1;
    while (index >= 0 && results[index] == value) {
        total_count++;
        index--;
    }
    printf("%d", total_count);
}