#C3289. Maximum Minimum Loyalty Points

    ID: 46699 Type: Default 1000ms 256MiB

Maximum Minimum Loyalty Points

Maximum Minimum Loyalty Points

You are given nn customers and kk gifts. Each customer has an associated loyalty point value. In order to maximize customer satisfaction, you want to distribute the gifts such that the minimum loyalty point among the chosen customers is as high as possible. Formally, you need to choose kk customers out of nn, and you would like to maximize the minimum loyalty point among those selected. It turns out that this is equivalent to selecting the kk customers with the highest loyalty points and then taking the kthk^\text{th} largest value.

For example, if n=5n = 5, k=3k = 3 and the loyalty points are [1, 2, 3, 4, 5], the optimal selection is to choose customers with points 5, 4, 3. The minimum among these is 3, which is the answer.

inputFormat

The input is given from standard input (stdin) as follows:

  • The first line contains an integer nn, the number of customers.
  • The second line contains an integer kk, the number of gifts to distribute.
  • The third line contains nn space-separated integers representing the loyalty points of the customers.

It is guaranteed that 1kn1 \leq k \leq n.

outputFormat

Print a single integer to standard output (stdout) representing the maximum possible value among the minimum loyalty points of the customers who receive gifts.## sample

5
3
1 2 3 4 5
3

</p>