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

using namespace std;

typedef long long LL;

int main() {
  int n, k; scanf("%d %d", &n, &k);
  vector<int> a(n);
  for (int i=0; i<n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end(), greater<int>());

  int res = 1;
  while (
    res < a.size()
    && (res < k
        || a[res] == a[res-1])) {
    ++res;
  }

  printf("%d\n", res);

  return 0;
}