BUNNIES - Bunnies
Pompom bunny has N strange eggs. The i-th egg is broken by tapping it exactly Ai times. Pompom needs to break K eggs as soon as possible for cooking a rice omelette. However she has been put in an uncomfortable situation. Someone has shuffled the eggs! Pompom knows the values Ai, however she doesn't know which egg is which. She'd like to minimize the worst-case number of taps. What is the minimal number?
Input
The first line contains an integer T, the number of test cases. Then T test cases follow. The first line for each test case has 2 integers N and K. Then next line has N integers A1, A2 ... AN.
Output
For each test case, print the minimal number of taps for the worst-case.
Constraints
1 <= T <= 10
1 <= K <= N <= 3000
1 <= Ai <= 1000000
Example
Input: 3 2 1 5 8 2 1 5 58 3 2 1 2 3 Output: 8 10 5
Explanation
In the first case, if a egg isn't broken after 5 taps, she should continue to tap the same egg.
In the second case, if a egg isn't broken after 5 taps, she should tap another egg 5 times.
hide comments
smso:
2020-03-27 19:10:00
1
|
|
alfa_razra1505:
2017-08-15 10:35:24
whats the output for
|
|
Prashant Khurana:
2014-02-09 12:53:05
@Himanshu, I too think it should be 20, take any 2 eggs. Hit each one of them 10 times. You are bound to break 1 of the egg. Last edit: 2014-02-09 14:29:37 |
|
himanshu jain:
2012-08-27 05:07:30
@Xunie J: why it should be 20? it should be 27 only because in the worst case pompon taps 9 times all the 3 eggs and which will result in 1 egg broken. |
|
chetan:
2012-07-29 11:18:59
can you please check my solution id, I believe it covers all possible cases but is still showing WA...the id is 7389887 Last edit: 2012-07-29 18:31:29 |
|
devu:
2012-07-29 10:57:38
@Chetan Dalal : Rethink Your Logic with Proof of Correctness..you will surey get it correct. Last edit: 2013-01-17 10:01:07 |
|
Xunie J:
2012-03-15 13:02:50
I think the answer for
|
|
Alex Anderson:
2012-02-11 03:38:02
This one was pretty fun. Nice problem |
|
Fernando Fonseca [ITA]:
2012-02-09 13:59:31
For that case, Pompom can tap all eggs 1 time, breaking both 1 eggs, then tap the remaining 4 one time each, breaking the 2 eggs. This gives a total of only 10 taps on the worst case. Last edit: 2012-02-09 14:00:24 |
|
Devil D:
2012-02-09 12:18:55
whats the output for
|
Added by: | Paulo Costa |
Date: | 2012-02-01 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | PUCP |