B - Awards of a Programming Contest Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君は、プログラミングコンテストの運営を担当しています。コンテストが終了し、いよいよ表彰式の準備を行うことになりました。

今回のコンテストには N 人の参加者がおり、i 番目の参加者はスコア A_i を獲得しました。

表彰では、スコアが高い方から少なくとも K 人に賞を授与します。ただし、公平性のため、K 位の参加者と同じスコアの参加者が他にもいる場合は、その全員にも賞を授与します。

厳密には、N 人のスコアを降順(大きい順)に並べた列を B_1, B_2, \ldots, B_NB_1 \geq B_2 \geq \cdots \geq B_N)とします。このとき、スコアが B_K 以上であるすべての参加者を表彰対象とします。

表彰対象となる参加者の人数を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 入力はすべて整数である。

入力

N K
A_1 A_2 \ldots A_N
  • 1 行目には、参加者の人数を表す整数 N と、表彰の基準となる順位を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各参加者のスコアを表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
  • A_ii 番目の参加者のスコアを表す。

出力

表彰対象となる参加者の人数を 1 行で出力せよ。


入力例 1

6 3
100 90 80 80 70 60

出力例 1

4

入力例 2

5 2
50 40 30 20 10

出力例 2

2

入力例 3

10 4
500 400 300 300 300 200 200 100 100 50

出力例 3

5

入力例 4

20 5
1000000000 999999999 888888888 888888888 777777777 777777777 777777777 666666666 555555555 444444444 333333333 222222222 111111111 100000000 99999999 88888888 77777777 66666666 55555555 44444444

出力例 4

7

入力例 5

1 1
1000000000

出力例 5

1

Score : 300 pts

Problem Statement

Takahashi is in charge of organizing a programming contest. The contest has ended, and it is now time to prepare for the award ceremony.

There are N participants in this contest, and the i-th participant earned a score of A_i.

In the awards, prizes will be given to at least the top K participants by score. However, for fairness, if there are other participants with the same score as the participant in K-th place, all of them will also receive prizes.

More precisely, let B_1, B_2, \ldots, B_N (B_1 \geq B_2 \geq \cdots \geq B_N) be the sequence of scores of the N participants sorted in descending order. Then, all participants whose score is at least B_K will be eligible for the award.

Find the number of participants who are eligible for the award.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers.

Input

N K
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of participants and an integer K representing the rank threshold for the award, separated by a space.
  • The second line contains integers A_1, A_2, \ldots, A_N representing the scores of each participant, separated by spaces.
  • A_i represents the score of the i-th participant.

Output

Print the number of participants eligible for the award in a single line.


Sample Input 1

6 3
100 90 80 80 70 60

Sample Output 1

4

Sample Input 2

5 2
50 40 30 20 10

Sample Output 2

2

Sample Input 3

10 4
500 400 300 300 300 200 200 100 100 50

Sample Output 3

5

Sample Input 4

20 5
1000000000 999999999 888888888 888888888 777777777 777777777 777777777 666666666 555555555 444444444 333333333 222222222 111111111 100000000 99999999 88888888 77777777 66666666 55555555 44444444

Sample Output 4

7

Sample Input 5

1 1
1000000000

Sample Output 5

1