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
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> tab;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    tab.push_back(x);
  }

  sort(tab.begin(), tab.end());
  for (int i = 0; i < n/2; ++i) {
    swap(tab[i], tab[n-i-1]);
  }

  int x = tab[k-1];

  for (int i = k; i < n; ++i) {
    if (tab[i] < x) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("%d\n", n);
}