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 k hours to do an important task while your bus journey will take n 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 k 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 n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ n) — the number of hours on the bus and the number of hours to do the task. The second line contains n space-separated integers ai (0 ≤ ai ≤ 100), ai is the fan speed at the i-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...

Related Contests

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