1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> a(n);
  for (auto &i: a) {
    scanf("%d", &i);
  }
  sort(a.begin(), a.end(), greater<int>());
  int res = k - 1;
  while (res < a.size() && a[res] == a[k - 1]) {
    res++;
  }
  printf("%d\n", res);
}