You are on page 1of 4

Problem No:1

Adam went shopping for his son’s birthday party. He wants to


buy the most expensive candle, balloon and cake under his
budget. Print the amount left after buying all three things.
If not possible to buy all the items, print -1.

Input:
The first line contains 4 space-separated integers a,x,y,z
where a = budget.
The second line contains x space-separated integers , the
price of each candle.
The third line contains y space-separated integers , the price
of each balloon.
The fourth line contains z space-separated integers , the
price of each cake.
Output:
The output will be a single integer.

Constraints
1≤a≤105
1≤x,y,z≤1000
The price of each each object is in the range [1, 10^6]
Sample Input:
80 3 6 5
16 12 33
13 29 35 78 25 46
44 52 40 13 8
Sample Output:
3
EXPLANATION:
Adam would buy 12+25+40=77. So the amount left will be 80-77
= 3.
Problem No :2
The Michael has a recipe he wishes to use for his guests, but
the recipe will make far more food than he can serve to the
guests. The Michael therefore would like to make a reduced
version of the recipe which has the same ratios of
ingredients, but makes less food. The Michael, however, does
not like fractions. The original recipe contains only whole
numbers of ingredients, and the Michael wants the reduced
recipe to only contain whole numbers of ingredients as well.
Help the Michael determine how much of each ingredient to use
in order to make as little food as possible.
Input
Input will begin with an integer T, the number of test cases.
Each test case consists of a single line. The line begins
with a positive integer N, the number of ingredients. N
integers follow, each indicating the quantity of a particular
ingredient that is used.
Output
For each test case, output exactly N space-separated integers
on a line, giving the quantity of each ingredient that the
Michael should use in order to make as little food as
possible.

Sample Input
3
2 4 4
3 2 3 4
4 3 15 9 6
Sample Output
1 1
2 3 4
1 5 3 2
Constraints
T≤100
2≤N≤50
All ingredient quantities are between 1 and 1000, inclusive.
Problem No: 3.
Michael loves to play with arrays by himself. Today, he has
an array A consisting of N distinct integers. He wants to
perform the following operation on his array A.

Select a pair of adjacent integers and remove the larger one


of these two. This decreases the array size by 1. Cost of
this operation will be equal to the smaller of them.
Find out minimum sum of costs of operations needed to convert
the array into a single element.

Input
First line of input contains a single integer T denoting the
number of test cases. First line of each test case starts
with an integer N denoting the size of the array A. Next line
of input contains N space separated integers, where the ith
integer denotes the value Ai.

Output
For each test case, print the minimum cost required for the
transformation.

Constraints
1 ≤ T ≤ 10
2 ≤ N ≤ 50000
1 ≤ Ai ≤ 105

Example
Input
2
2
3 4
3
4 2 5
Output
3
4
Explanation
Test 1 : Michael will make only 1 move: pick up both the
elements (that is, 3 and 4), remove the larger one (4),
incurring a cost equal to the smaller one (3).

You might also like