Destroy The Asteroids
All submissions for this problem are available.Rick has set out on a space journey to destroy asteroids. He has identified $N$ different groups (numbered from $1$ to $N$) of Asteroids. The size of groups $G_1$, $G_2$, ...., $G_n$ are given. Using his superpowers, he can destroy exactly 1 asteroid from $K$ different groups in 1 minute. He doesn't want to waste his superpower so he will stop once there are less than $K$ groups available. You want to watch him destroy these asteroids for as long as possible. Can you find the maximum number of minutes you can keep him busy? ###Input: - First line will contain $N$ and $K$, number of groups and number of different groups he can destroy at once. - Second line contains N integers ($G_1$, $G_2$, ....,$G_n$) denoting each group's size. ###Output: Print one integer denoting the number of minutes he will take to complete the given task. ###Constraints - $1 \leq N \leq 10^6$ - $ 1 \leq K \leq N$ - $1 \leq A_i \leq 10^9$ ###Sample Input: 2 2 2 3 ###Sample Output: 2 ###EXPLANATION: After one minute, asteroid groups will look like [1,2] After two minutes, asteroid groups will look like [0,1] He will stop after two minutes since there are less than 2 groups which have an asteroid.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.