#C9214. Maximum Uniform Brightness

    ID: 53283 Type: Default 1000ms 256MiB

Maximum Uniform Brightness

Maximum Uniform Brightness

You are given a zone with n lights, where each light has a maximum brightness level. Your task is to determine the highest uniform brightness level that can be applied to exactly k lights in the zone. Note that for any set of k lights, the uniform brightness level you can use is limited by the light with the lowest maximum brightness in that set. It turns out that if you sort the brightness levels in descending order, the answer is simply the kth element in the sorted list.

In mathematical terms, if the sorted brightness array is \(B = [b_1, b_2, \ldots, b_n]\) such that \(b_1 \geq b_2 \geq \cdots \geq b_n\), then the answer is \(b_k\).

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains two integers n and k separated by a space, where n is the number of lights, and k is the number of lights to set to the same brightness.
  • The second line contains n integers separated by spaces, representing the maximum brightness levels of the lights.

outputFormat

Output the highest uniform brightness level (an integer) to stdout. The output should be exactly the integer result followed by a newline.

## sample
5 3
60 80 90 70 50
70

</p>