1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

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

  int val = v[m-1];
  while(m<v.size() && v[m] == val) m++;
  printf("%d\n",m);
}