I. Richie Rich
Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth AA billion dollars and have no liabilities. He aims to increase his assets by XX billion dollars per year.
Also, all the richest people in Chefland are not planning to grow and maintain their current worth.
To be the richest person in Chefland, he needs to be worth at least BB billion dollars. How many years will it take Chef to reach his goal if his value increases by XX billion dollars each year?
Input
- The first line contains an integer TT, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, three integers AA, BB, XX.
Output
For each test case, output in a single line the answer to the problem.
Constraints
- 1≤T≤21 0001≤T≤21 000
- 100≤A<B≤200100≤A<B≤200
- 1≤X≤501≤X≤50
- XX divides B−AB−A
Subtasks
Subtask #1 (100 points): Original constraints
Sample 1:
Input
Output
3
100 200 10
111 199 11
190 200 10
10
8
1
Explanation:
Test Case 1: Chef needs to increase his worth by 200−100=100200−100=100 billion dollars and his increment per year being 1010 billion dollars, so it will take him 10010=1010100=10 years to do so.
Test Case 2: Chef needs to increase his worth by 199−111=88199−111=88 billion dollars and his increment per year being 1111 billion dollars, so it will take him 8811=81188=8 years to do so.
Test Case 3: Chef needs to increase his worth by 200−190=10200−190=10 billion dollars and his increment per year being 1010 billion dollars, so it will take him 1010=11010=1 year to do so.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int A = sc.nextInt();
int B = sc.nextInt();
int X = sc.nextInt();
int years = (B - A) / X;
System.out.println(years);
}
sc.close();
}
}
II. Vaccine Dates
Chef has taken his first dose of vaccine DD days ago. He may take the second dose no less than LL days and no more than RR days since his first dose.
Determine if Chef is too early, too late, or in the correct range for taking his second dose.
Input Format
- First line will contain TT, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, three integers D,L,RD,L,R.
Output Format
For each test case, print a single line containing one string – “Too Early” (without quotes) if it’s too early to take the vaccine, “Too Late” (without quotes) if it’s too late to take the vaccine, “Take second dose now” (without quotes) if it’s the correct time to take the vaccine.
Constraints
- 1≤T≤1051≤T≤105
- 1≤D≤1091≤D≤109
- 1≤L≤R≤1091≤L≤R≤109
Subtasks
- Subtask 1 (100 points): Original constraints
Sample 1:
Input
Output
4
10 8 12
14 2 10
4444 5555 6666
8 8 12
Take second dose now
Too Late
Too Early
Take second dose now
Explanation:
Test case 1: The second dose needs to be taken within 88 to 1212 days and since the Day 1010 lies in this range, we can take the second dose now.
Test case 2: The second dose needs to be taken within 22 to 1010 days since Day 1414 lies after this range, it is too late now.
Test case 3: The second dose needs to be taken within 55555555 to 66666666 days and since the Day 44444444 lies prior to this range, it is too early now.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T --> 0) {
int D = sc.nextInt();
int L = sc.nextInt();
int R = sc.nextInt();
if (D < L) {
System.out.println("Too Early"); }
else if (D > R) {
System.out.println("Too late"); }
else {
System.out.println("Take second dose now");
}
}
}
}
III. Hoop Jump
You and your friend are playing a game with hoops. There are NN hoops (where NN is odd) in a row. You jump into hoop 11, and your friend jumps into hoop NN. Then you jump into hoop 22, and after that, your friend jumps into hoop N−1N−1, and so on.
The process ends when someone cannot make the next jump because the hoop is occupied by the other person. Find the last hoop that will be jumped into.
Input
- The first line contains an integer TT, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, a single integer NN.
Output
For each testcase, output in a single line the answer to the problem.
Constraints
- 1≤T≤1051≤T≤105
- 1≤N<2⋅1051≤N<2⋅105
- NN is odd
Subtasks
Subtask #1 (100 points): original constraints
Sample 1:
Input
Output
2
1
3
1
2
Explanation:
Test Case 11: Since there is only 11 hoop, that’s the only one to be jumped into.
Test Case 22: The first player jumps into hoop 11. The second player jumps into hoop 33 and finally the first player jumps into hoop 22. Then the second player cannot make another jump, so the process stops.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int i=0;i<T;i++){
int N = sc.nextInt();
System.out.println((N+1)/2);
}
}
}
IV. The Two Dishes
Chef prepared two dishes yesterday. Chef had assigned the tastinesstastiness T1T1 and T2T2 to the first and to the second dish respectively. The tastiness of the dishes can be any integerinteger between 00 and NN (both inclusive).
Unfortunately, Chef has forgotten the values of T1T1 and T2T2 that he had assigned to the dishes. However, he remembers the sum of the tastiness of both the dishes – denoted by SS.
Chef wonders, what can be the maximum possible absolute difference between the tastiness of the two dishes. Can you help the Chef in finding the maximum absolute difference?
It is guaranteed that at least one pair {T1,T2}{T1,T2} exist such that T1+T2=S,0≤T1,T2≤NT1+T2=S,0≤T1,T2≤N.
Input Format
- The first line of input contains a single integer TT, denoting the number of testcases. The description of the TT testcases follows.
- The first and only line of each test case contains two space-separated integers NN, SS, denoting the maximum tastiness and the sum of tastiness of the two dishes, respectively.
Output Format
For each testcase, output a single line containing the maximum absolute difference between the tastiness of the two dishes.
Constraints
- 1≤T≤1031≤T≤103
- 1≤N≤1051≤N≤105
- 1≤S≤2⋅1051≤S≤2⋅105
Sample 1:
Input
Output
3
3 1
4 4
2 3
1
4
1
Explanation:
Test Case 11: The possible pairs of {T1,T2}{T1,T2} are {0,1}{0,1} and {1,0}{1,0}. Difference in both the cases is 11, hence the maximum possible absolute difference is 11.
Test Case 22: The possible pairs of {T1,T2}{T1,T2} are {0,4}{0,4}, {1,3}{1,3}, {2,2}{2,2}, {3,1}{3,1} and {4,0}{4,0}. The maximum possible absolute difference is 44.
Test Case 33: The possible pairs of {T1,T2}{T1,T2} are {1,2}{1,2} and {2,1}{2,1}. Difference in both the cases is 11, and hence the maximum possible absolute difference is 11.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i=0;i<T;i++){
int N = sc.nextInt();
int S = sc.nextInt();
if (N>=S) {
System.out.println(S); }
else {
System.out.println((2*N)-S);
}
}
}
}
V. Problem Category
Chef prepared a problem. The admin has rated this problem for xx points.
A problem is called :
- Easy if 1≤x<1001≤x<100
- Medium if 100≤x<200100≤x<200
- Hard if 200≤x≤300200≤x≤300
Find the category to which Chef’s problem belongs.
Input Format
- The first line contains TT denoting the number of test cases. Then the test cases follow.
- The first and only line of each test case contains a single integer xx.
Output Format
For each test case, output in a single line the category of Chef’s problem, i.e whether it is an Easy
, Medium
or Hard
problem. The output is case sensitive.
Constraints
- 1≤T≤501≤T≤50
- 1≤x≤3001≤x≤300
Subtasks
- Subtask 1 (100 points): Original constraints
Sample 1:
Input
Output
3
50
172
201
Easy
Medium
Hard
Explanation:
Test case 11: The problem with rating x=50x=50 is an easy problem as 1≤50<1001≤50<100.
Test case 22: The problem with rating x=172x=172 is a medium problem as 100≤172<200100≤172<200.
Test case 33: The problem with rating x=201x=201 is a hard problem as 200≤201≤300200≤201≤300.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
int x = sc.nextInt();
if (1 <= x && x < 100) { System.out.println("Easy"); }
else if (100 <= x && x < 200) { System.out.println("Medium"); }
else if(200 <= x && x <= 300) {System.out.println("Hard"); }
}
}
}
VI. Programming Languages
Chef is a software developer, so he has to switch between different languages sometimes. Each programming language has some features, which are represented by integers here.
Currently, Chef has to use a language with two given features AA and BB. He has two options — switching to a language with two features A1A1 and B1B1, or to a language with two features A2A2 and B2B2. All four features of these two languages are pairwise distinct.
Tell Chef whether he can use the first language, the second language or neither of these languages (if no single language has all the required features).
Input Format
- The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
- The first and only line of each test case contains six space-separated integers A,B,A1,B1,A2,B2A,B,A1,B1,A2,B2.
Output Format
For each test case, print a single line containing the integer 11 if Chef should switch to the first language, or 22 if Chef should switch to the second language, or 00 if Chef cannot switch to either language.
Constraints
- 1≤T≤2881≤T≤288
- 1≤A,B,A1,B1,A2,B2≤41≤A,B,A1,B1,A2,B2≤4
- A,BA,B are distinct
- A1,B1,A2,B2A1,B1,A2,B2 are pairwise distinct
Subtasks
Subtask #1 (100 points): original constraints
Sample 1:
Input
Output
3
1 2 2 1 3 4
3 4 2 1 4 3
1 2 1 3 2 4
1
2
0
Explanation:
Example case 1: The first language has the required features — features 11 and 22.
Example case 2: The second language has the required features — features 33 and 44.
Example case 3: Neither language has both features 11 and 22.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
int A = sc.nextInt();
int B = sc.nextInt();
int A1 = sc.nextInt();
int B1 = sc.nextInt();
int A2 = sc.nextInt();
int B2 = sc.nextInt();
if ((A1 == A || B1 == A) && (A1 == B || B1 == B)) { System.out.println(1);}
else if ((A2 == A || B2 == A) && (A2 == B || B2 == B)) {System.out.println(2);}
else {System.out.println(0);}
}
}
}
VII. Chef and Spells
Chef has three spells. Their powers are AA, BB, and CC respectively. Initially, Chef has 00 hit points, and if he uses a spell with power PP, then his number of hit points increases by PP.
Before going to sleep, Chef wants to use exactly two spells out of these three. Find the maximum number of hit points Chef can have after using the spells.
Input Format
- The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
- The first and only line of each test case contains three space-separated integers AA, BB, and CC.
Output Format
For each test case, print a single line containing one integer — the maximum number of hit points.
Constraints
- 1≤T≤1041≤T≤104
- 1≤A,B,C≤1081≤A,B,C≤108
Subtasks
Subtask #1 (100 points): original constraints
Sample 1:
Input
Output
2
4 2 8
10 14 18
12
32
Explanation:
Example case 1: Chef has three possible options:
- Use the first and second spell and have 4+2=64+2=6 hitpoints.
- Use the second and third spell and have 2+8=102+8=10 hitpoints.
- Use the first and third spell and have 4+8=124+8=12 hitpoints.
Chef should choose the third option and use the spells with power 44 and 88 to have 1212 hitpoints.
Example case 2: Chef should use the spells with power 1414 and 1818.
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i=0; i<T; i++) {
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
int D = (A+B);
int E = (B+C);
int F = (A+C);
if((D > E) && (D > F)) { System.out.println(D);}
else if ((E > D) && (E > F)) { System.out.println(E);}
else if ((F > D) && (F > E)) { System.out.println(F);}
else if ((D == E) && (E == F)) {System.out.println(D);}
else if (E == F) {System.out.println(E);}
else if (D == F) {System.out.println(D);}
else if (D == E) {System.out.println(D);}
}
}
}