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
45
46
47
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
# pragma GCC diagnostic warning "-Wall"
# pragma GCC diagnostic warning "-Wextra"
# pragma GCC diagnostic warning "-Wformat=2"
# pragma GCC diagnostic warning "-Wnull-dereference"
# pragma GCC diagnostic warning "-Wduplicated-branches"
# pragma GCC diagnostic warning "-Wduplicated-cond"
# pragma GCC diagnostic warning "-Wfloat-equal"
# pragma GCC diagnostic warning "-Wshadow"
# pragma GCC diagnostic warning "-Wconversion"
# pragma GCC diagnostic warning "-Wlogical-op"
# pragma GCC diagnostic warning "-Wvector-operation-performance"
# pragma GCC diagnostic warning "-Wdisabled-optimization"
# pragma GCC diagnostic warning "-Wunsafe-loop-optimizations"
# pragma GCC diagnostic warning "-Wdouble-promotion"
#endif
#pragma GCC target "arch=ivybridge", "tune=ivybridge"
#if defined(ONLINE_JUDGE) || !defined(__OPTIMIZE__)
# pragma GCC optimize "Ofast", "inline", "unroll-loops", "ipa-pta", "no-rtti", \
  "no-exceptions", "nothrow-opt", "strict-enums", "stdarg-opt", "tracer"
# pragma GCC target "inline-all-stringops"
#endif
#define rangeof(c) (c).begin(), (c).end()

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<int> nums(n);
  for(auto &num: nums) {
    cin >> num;
  }
  sort(rangeof(nums), greater<int>());
  
  int i = k - 1;
  while(i + 1 < n && nums[i] == nums[i + 1]) i++;
  cout << i + 1 << "\n";
}