#P9044. Gift Distribution
Gift Distribution
Gift Distribution
There are \( n \) participants in a contest, and the \( i \)-th participant has a score of \( a_i \). The organizers have decided to distribute at least \( k \) gifts. However, if there exist two participants \( x \) and \( y \) (with \( 1 \le x, y \le n \)) such that \( a_x \ge a_y \) but participant \( x \) does not receive a gift while participant \( y \) does, then participant \( x \) will be unsatisfied.
To keep everyone satisfied, the organizers want to choose a set of recipients that satisfies the following:
- If a participant with a lower score receives a gift, then every participant with a score at least as high must also receive a gift.
- At least \( k \) gifts must be given.
Your task is to determine the minimum number of gifts that must be awarded so that everyone is satisfied.
Note: If the \( k \)-th highest score is \( T \), then all participants with a score \( \ge T \) must receive a gift. In other words, the answer is the count of participants with scores at least \( T \).
inputFormat
The first line contains two integers \( n \) and \( k \) (\( 1 \le k \le n \le 10^5 \)).
The second line contains \( n \) integers \( a_1, a_2, \ldots, a_n \) representing the scores of the participants (\( 1 \le a_i \le 10^9 \)).
outputFormat
Output a single integer: the minimum number of gifts that must be awarded to keep every participant satisfied.
sample
5 2
3 1 2 2 1
3