Theft at World Bank
Submissions: 866   Accuracy:

3.98%

  Difficulty: Easy   Marks: 2

The world’s most successful thief ever, Albert Spaggiari was planning for his biggest theft ever on the world bank. He decides to carry a sack, which can carry a maximum of C kgs. The day finally arrives, also arrives Albert at the gates of the bank. Luckily, there wasn’t any guard on the gate. He enters the locker and was amazed to see large blocks of gold. This also made him worry a bit, as it was difficult to carry such blocks and this can reduce the amount of gold he can carry. All the blocks have some profit value associated with them.(i.e. that much profit will be earned by using that block fully). So, he calls his friend and asks him to bring a gas cutter. His friend came after sometime, and they both start to collect and cut the blocks according to their needs. The story isn’t over yet, Albert hates symmetry, so he can’t use blocks whose weight is a perfect square.

Now, you need to find out the maximum profit that he can earn.


Input:
The first line of input contains T denoting number of test cases. The first line of each test case contains two integers N and C, denoting the number of blocks and the capacity of Albert’s sack. Next line contains N space separated pairs contain 2 integers each, Wi and Pi, denoting the weight and profit of the ith block.

Output:
For each test case output a single line containing the maximum profit that he can earn(with a precision of 10-3).


Constraints:
1<= T <= 100
1<= N <= 103
1<=C<=1018
1<=Wi<=109
1<=Pi<=109

 

Example:
Input:

2
3 10
4 8 5 5 7 4
2 3
1 2 3 4

Output:
7.857
4.000

 

Explanation:
In first test case as first block’s weight 4, is a perfect square, he can’t use this block. Now with the remaining blocks the most optimal way is to use 2nd block completely and cut 5kg piece from the 3rd block to get a total profit of 5+2.857=7.857.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Tanuj Yadav
Author: tanujyadav97


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.