
1. There should be exactly one base flavor.
2. Toppings can be one or more or none.
3. There are at most two toppings of each type.
Let N = 2 , M = 2 , K = 10, FLAVOR = [1,7] , TOPPING = [3, 4] , K = 10
Here we can make a dessert with the base flavor of price 7 and adding 1 topping of price 3. Which will cost 7 + 3 = 10, which is exactly equal to k, so the closest possible price would be 10.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains an integer ‘N’ representing the number of base FALVOURS.
The second line of each test case contains ‘N’ integer representing the cost base FLAVOURS.
The third line of each test case contains an integer ‘M’ representing the number of TOPPINGS.
The second line of each test case contains ‘M’ integer representing the cost TOPPINGS.
The fifth and last line of each test case contains an integer ‘K’ representing the target price for dessert.
For each test case, print a single line containing a single integer denoting the closest possible price of the dessert to the target price.
The output of each test case will be printed in a separate line.
You don’t need to print anything or take input. It already has been taken care of. Just implement the function.
1 <= T <= 5
1 <= N, M <= 10
1 <= FLAVOUR[i] , TOPPINGS[i] <= 10 ^ 4
1 <= K <= 10 ^ 4
Time limit: 1 sec.
There are 3 ways to make a dessert
Implement this with recursion since we have 3 choices at each instant.
We will now take a particular base flavor and start adding toppings to it in the above ways.
Combination Sum III
Combination Sum III
Combination Sum III
Combination Sum III
Combination Sum III
Generate All Strings
Generate All Strings
Generate All Strings
Generate All Strings
8-Queen Problem
Sequential Digits
Expression Add Operators