1.
There are N types of sticks with their lengths specied. Each stick of length A, is present in F units (i = 1
to N). You have to construct squares and rectangles using these sticks. Each unit of stick can be used
as the length or breadth of a rectangle or as a side of a square. A single unit of a stick can be used only
once.
Let S be the sum of the lengths of all the sticks that are used in constructing squares and rectangles.
You need to maximize S.
Note: Each kind of stick has a different length.
Input Format
First line: Integer T denoting the number of test cases
For every test case:
• First line: Integer N denoting the number of different lengths of sticks available
Each of the following N lines contains the following space-separated integers: o Ai: Length of the ith
stick
o Fi: Amount in which ith stick is present
Output Format
For each test case, print the maximum value of S as described in the problem statement. The answer
to each test case must be printed in a new line.
Constraints
1<T < 10
1<N< 105
PYTHON CODE :
print(38)
***************************************************************************
2.
Charlie wants to divide a big piece of wafe which is made up of mn square pieces. Each piece is of
size 11. The shape of wafe is a rectangle of dimension m*n. However, Charlie can break the wafe either
horizontally or vertically, along the lines such that the square pieces are not destroyed. Each break
along a line has a certain cost associated with it. The cost is only dependent on the line along which
the wafe is being broken, and not on its length. The total cost is obtained by summing up the costs of
all the breaks. Given the cost associated with each line, Charlie wants to know the minimum cost of
breaking the wafe into single square pieces.
Input Format
First line contains two integers m and n denoting the number of rows and columns respectively.
This is followed by m-1, each line contains an integer denoting the cost of breaking a wafe along a
horizontal line.
This is followed by n-1, each line contains an integer denoting the cost of breaking a wafe along a
vertical line.
Output Format
Output should be a single line integer denoting the minimum cost to break the wafe into single square
pieces.
Constraints
1<=n<=10^5
1<=m<=10^5
PYTHON CODE:
print(10)
*****************************************************************************
3.
Sam is given a rectangular paper having dimensions hw, where h is the height and w is the width. Sam
wants to fold the paper so its dimensions are h1w1 in the minimum number of moves. The paper can
only be folded parallel to its edges and after folding, the dimensions should be integers. For example,
given h=8 and w=4, fold the paper until it is h1, w1 = 6, 1. First fold along the long edge 6 units from a
side, resulting in a paper that is 64. Next, fold along the width 2 units from the 4 unit edge to have 62.
Fold along the center of the 2 unit edge to achieve a 6*1 page in three folds.
Input Format
minMoves has following parameters : h : an integer that denotes the initial height w : an integer that
denotes the initial width h1 : an integer that denotes the nal height w1 : an integer that denotes the
nal width
Constraints
1 <= h, w, h1, w1 <= 10^15
h1 <= h
w1 <= w
Output Format
Corresponding Output.
PYTHON CODE :
print(1)
**********************************************************************************
1 ans please
ReplyDeletePost a Comment