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
#include <stdio.h>
using namespace std;

int main(int argc, char const *argv[]) {
  int playerNum, shirtsNum, playerPoints = 0, result = 0, i, j, k;
  bool finded = false, eq = false;
  if (!scanf("%d %d", &playerNum, &shirtsNum)) return 1;

  int points[playerNum];

  for (i = 0; i < playerNum; ++i) {
    if (!scanf("%d", &playerPoints)) return 1;
    finded = false;

    for (j = 0; j < i; ++j) {
      if (playerPoints > points[j]) {
        finded = true;
        for (k = i; k > j; --k) {
          points[k] = points[k-1];
        }
        points[j] = playerPoints;
        break;
      }
    }

    if (!finded) {
      points[i] = playerPoints;
    }
  }

  result = shirtsNum;
  playerPoints = points[shirtsNum - 1];
  for (i = shirtsNum; i < playerNum; ++i) {
    if (playerPoints == points[i]) {
      ++result;
    } else {
      break;
    }
  }

  printf("%d", result);

  return 0;
}