Professional Documents
Culture Documents
Little Aliya stood first in her school this year. Hearing this news,
her father gifted her a rectangular chocolate bar. Little Aliya wants
to share the chocolate bar with her younger brother Hasan. She
divided the chocolate bar into two parts. To be sure if she divided
the chocolate bar into two almost equal parts, she has to know
the area of the divided parts. As little Aliya doesn't know
geometry, she wants you to help her.
You’ll be given the ratio of the two divided parts. You’ve to tell her
the area of the divided parts.
Input
The first line contains two integers a and b (1 ≤ a, b ≤ 1000),
indicating the height and width of the chocolate bar.
Output
For each test case, print two integers a1, a2 - the area of the two
divided parts. The answer will be considered correct if its absolute
or relative error does not exceed 10^{-4}10−4.
Sample
Input Output
4 5 8.0000 12.0000
2 3
In the first test case, if we divide the chocolate bar into two
parts as (4 ✕ 2) and (4 ✕ 3) then the ratio of the area will be
(2 ∶ 3).
B. Diagonals
100 Points · Limits 1s, 512 MB
Given an array of n integers. All integers of the given array are
pairwise distinct. Your task is to place each element of the array
at the lattice points of the diagonals of a two-dimensional
coordinate system i.e. at position (i, j) such that, a_kak = i + j.
Input
The first line contains a single integer t (1≤ t ≤ 100). then t test
cases follow.
It is guaranteed that the sum of n over all test cases does not
exceed 10^5105.
Output
For each test case, print a single integer X - the maximum
number of elements of the same diagonal.
Sample
Input Output
1 2
3
5 11 10
After the city of Berk started living in harmony with the dragons,
there are now many Dragon riders in the village. To entertain
them, Hiccup decided to invent a game.
The train containing the sheep will start moving from the position
(1,1). And it will move back and forth along the main diagonal
each second as shown below:
(1,1),(2,2),(3,3),..............(n,n),(n-1,n-1)(n-2,n-2)(n-3,n-3),..........
You will be given the initial position of the players. Can you find
the minimum time needed for the dragon riders to reach the
sheep?
Output
You have to output a single line for each test case denoting the
minimum time needed for the players to reach the sheep.
Sample
Input Output
2 0
1
1 1
1 1
4 5
4 1
3 2
Input Output
4 3
2 4
1 4
In the second test case, the second player will move from (3,2) to
(2,2) in 1 second. and the train will move from (1,1) to (2,2) in one
second. so the player 2 can reach the train in one second.
D. Beautiful City
100 Points · Limits 1s, 512 MB
There is a country named ‘A’ which has n city. The cities are
connected by (n-1) two way roads. It is guaranteed that there is
no cycle and all cities are connected. Those cities are beautiful
which are connected with at most 1 city.
In this problem, you are given a city ‘x’ to find the distance of the
nearest beautiful city from x.
Input
The first line of input contains an integer n denoting the number of
cities in country ‘A’. The cities are numbered from 1, 2, 3, …., n.
Then there are n-1 lines describing the roads. Each line contains
two integers u and v - there is a road between city u and v.
Output
For each query output the distance of the nearest beautiful city.
Sample
Input Output
5 1
1 2 0
1 3
3 4
3 5
2
3
5
Gandalf wants to count how many magical words there are in his
dictionary, help him.
Input
Each test contains multiple test cases. The first line contains the
number of test cases T (1 ≤ T ≤ 10). Description of the test cases
follows.
Sample
Input Output
2 1
4 1
half
phoenix
blood
halfblood
3
ab
goblet
abab
F. Attentiveness
100 Points · Limits 1s, 512 MB
Jamil sir is really concerned about student’s attentiveness in the
class. Recently he got an idea. He will track students’ attendance
from Zoom Meeting by using their chat responses. He will ask
them some questions in a zoom meeting session and students
may or may not respond to those questions. A response will be
valid for a question if it is written after that question is asked and
till the next question occurs from Jamil sir. If Jamil sir
asked X questions, then Jamil sir will consider a student present if
he responds to at least ⌈ X/2 ⌉ different questions
( here ⌈A⌉ means ceil of A).
Sometimes Jamil sir may write normal chat which will not be
considered as a question.
Input
Input will consist of some line. Which will represent one of those -
Jamil sir’s question or Jamil sir’s random chat or student’s
response for any question.
There will not be more than 500 lines in total and each line will
consist of at most 100 characters.
Output
Print the IDs of the students who will be considered as present
according to the above-mentioned rules. You should print the IDs
in lexicographically ascending order.
Sample
Input Output
He wants to take any two cities from the map and calculate the
absolute difference of values of those two cities. He can’t use
those two cities again, so he will cut off the cities from the map by
using a pencil. Then he will take another two cities and calculate
the absolute difference and cut those cities off. He will continue
this until all the cities on the map are cut off. After calculating all
the absolute differences he will sum them up.
Input
At first, you will be given an even integer N, the number of cities.
You will be given N positive integers after that which are the
values of each city. Here,
1 <= N <= 10^5
Output
You will have to calculate the maximum sum according to the
above-mentioned way.
Sample
Input Output
4 2
5 6 4 5
Input Output
Here, He can select cities 1 and 3 first, with values 5 and 4 respectively. The absolu
difference between these two values is 1. Then the cities 2 and 4 are selected. Again
the absolute difference is 1. So the sum is 2. It can be proven that the sum over all
absolute differences, in this case, can not be more than 2.
H. Optimus PRIME!!
100 Points · Limits 1s, 512 MB
Input
The first line will contain a single integer T (1 ≤ T ≤ 100000)
- denoting the number of test cases.
If the answer is “YES”, you have to print another line where you
have to print the prime factorization of N in ascending order.
Sample
Input Output
3 YES
30 2 3 5
100 NO
70 NO