Fair Competition

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 512M

Author:
Problem type

CCC has just finished, and the organizer is trying to choose N contestants to put on the honour roll. If someone who gets a score of x is on the honour roll, then to keep the competition fair, every contestant who gets a score greater or equal to x should also be on the honour roll. Write a program to determine the maximum number of people who will be on the honour roll so that the number is not greater than N.

Input Specification

The first line contains M and N (1 \le N \le M \le 2 \times 10^4), indicating the total number of contestants and the expected number of people on the honour roll, respectively.

The next line contains M space-separated integers a_i (0 \le a_i \le 75), representing the score of i-th contestant.

Output Specification

Output one integer denotes the maximum number of people on the honour roll to keep competition fair and not greater than N.

Sample Input 1

5 2
1 2 3 3 4

Sample Output 1

1

Explanation

The organizer cannot only put 2 contestants on the honour roll. The optimal way is to only put the contestant who scored 4 on the honour roll.

Sample Input 2

5 3
2 2 2 2 4

Sample Output 2

1

Sample Input 3

8 5
1 1 2 2 3 3 3 3

Sample Output 3

4

Comments

There are no comments at the moment.