Question: Alice is throwing a birthday party for her son. She initially has n bowls of chocolates (c1, c2, c3... cn) are the number of chocolates

Alice is throwing a birthday party for her son. She initially has n bowls of chocolates (c1, c2, c3... cn) are the number of chocolates in each bowl) and she needs to distribute them among the children (one bowl each child), But k children arrive at the party (k>=n). Now she needs to prepare k bowls of chocolates. For that, she needs to transfer chocolates from the already filled bowls to the empty ones. Also, the calorie intake of a child by eating a bowl of chocolate is m² (where m is the number of chocolates in that bowl). She needs to divide the chocolates into k bowls such that the calorie intake per child can be minimized. Input Format The first line contains an integer t, denoting the number of test cases. The next line contains two integer n and k (1<=n<=k=104): the initial number of bowls and the number of children arrived. The next line contains n integer c1, c2, c3... cn (1<=ci<=105): chocolates in each bowl It is guaranteed that the sum of all ci is at least k. Output Format: Output one integer: the minimum sum of calorie inta of the children. 

Sample Testcase #0 

Testcase

 Input 

1

 3 6 

 3 2 1 

Testcase Output

 6

Step by Step Solution

3.40 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!