Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Magic Moments

By dhruba_1603088 · Limits 1s, 512 MB

You are going to a village by bus.

You need kk hours to do an important task while your bus journey will take nn hours.

You know that the speed of the fan in the bus changes every hour. The fan is measured on a scale from 0 to 100, where 0 is very slow and 100 is too fast. Bus authority has told you the fan speed schedule for all n hours.

You want to do your task only when the fan is fast, as much as possible. So, you have to choose kk hours from your bus journey when you will do the task such that minimum speed of fan among the selected hours is maximum.


The first input line contains two integers nn and kk (1n10001 ≤ n ≤ 1000, 1kn1 ≤ k ≤ n) — the number of hours on the bus and the number of hours to do the task. The second line contains nn space-separated integers aia_i (0ai1000 ≤ a_i ≤ 100), aia_i is the fan speed at the ii-th hour.


Print the minimum fan speed in which you will do the task.


15 1
0 78 24 24 61 60 0 65 52 57 97 51 56 13 10



90% Solution Ratio

riyad000Earliest, Jan '20

riyad000Fastest, 0.0s

NX4338Lightest, 0 B

bokaifShortest, 72B


Login to submit


You have to take the largest k numbers from the n numbers given in input and print the minimum numbe...

Toph uses cookies. By continuing you agree to our Cookie Policy.