Help a Thief!!!
Submissions: 1364   Accuracy:

30.97%

  Difficulty: Basic   Marks: 1

You have to help a thief to steal as many as GoldCoins as possible from a GoldMine. There he saw N Gold Boxes an each Gold Boxes consists of Ai Plates each plates consists of Aj Gold Coins, Each Box consist of plates with exactly same number of GoldCoins per plate. Your task is to print the maximum gold coins theif can steal.

Input:
First line consists of T test cases. Each test case consists of three lines.
First line of each test case consistss of an Integer nT denoting the number of plates theif can steal.
Second line of each test case consists of an Integer N denoting the number of Gold Boxes available in the gold mine.
Third line of each test case consists of 2*N spaced Integers Ai,Aj dentoning number of plates in each box and number of gold coins in each plates respectively.

Output:
Print the respective result in each line.

Constraints:
1<=T<=20
1<=nT,Ai<=20
1<=N<=20
1<=Aj<=100

Example:
Input:

1
3
3
1 3 2 2 3 1
Output:
7

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

Contributor: Saksham Raj Seth
Author: saksham seth


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.