MAIN8_C - Shake Shake Shaky

no tags 

 

Shaky has N (1<=N<=50000) candy boxes each of them contains a non-zero number of candies (between 1 and 1000000000). Shakey want to distibute these candies
among his K (1<=K<=1000000000) IIIT-Delhi students. He want to distibute them in a way such that:

Shaky has N (1<=N<=50000) candy boxes each of them contains a non-zero number of candies (between 1 and 1000000000). Shakey want to distibute these candies among his K (1<=K<=1000000000) IIIT-Delhi students. He want to distibute them in a way such that:

1. All students get equal number of candies.

2. All the candies which a student get must be from a single box only. 

As he want to make all of them happy so he want to give as many candies as possible. Help Shaky in finding out what is the  maximum number of candies which a student can get.

Input

First line contains 1<=T<=20 the number of test cases. Then T test cases follow. First line of each test case contains N and K. Next line contains N integers, ith of which is the number of candies in ith box.

Output

For each test case print the required answer in a seperate line.

Example

Input:
2
3 2 
3 1 4
4 1
3 2 3 9

Output:
3
9

hide comments
roncoder: 2022-02-05 12:19:17

just a tip, ensure check() function time complexity to be according 'n' not 'k' (k is 10^9)

sk128: 2021-08-08 10:30:08

Good Question for learning purpose . Cheers to the problem setter _/\_ .

beowulf_rohan: 2020-08-29 23:37:07

try mid = start + (end-start+1)/2
and if mid = 0, then return 0

shantanu404: 2020-04-28 21:01:23

This problem can be solved without using 'long long', you want use 'low + (high - low)/2' for calculating 'mid'. That would avoid any kind of overflow and this is how you should always do this.

Last edit: 2020-04-28 21:03:32
tushar260900: 2019-12-26 07:43:23

submitting using binary search and long long also
still getting tle

mayanku1999: 2019-09-03 13:26:26

Binary Search application based ques, just like Aggressive cows

Last edit: 2019-09-03 13:26:44
maratha: 2019-08-11 12:30:58

BS FTW!!

divergent42: 2019-07-05 09:41:37

Good question

exesharkx: 2019-04-10 15:37:51

print 0 if not possible

sajalagrawal14: 2019-01-28 13:46:01

ac in one go


Added by:Mahesh Chandra Sharma
Date:2011-04-20
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem used for NSIT-IIITA Main contest #8