Starters-84 Contest CodeChef
All the Problem Statements and their Solution Codes are mentioned Below:-
Me After Winning a Game with an FM after 10 Consecutive LossThe Last Problem of the Contest, Sum OR is still being processed by my Obtuse Brain, well, CODE SPEAKS FOR ITSELF!! ;)
Digit Operation:
Problem Statement:-
You are given arrays and , each consisting of strings, and a positive integer .
For all , both and consist of characters from to (both inclusive).
You can perform the following types of operations on array :
- Type : Choose two indices and and swap any character of with any character of . The cost of this operation is .
- Type : Choose an index and replace one character of with any character from to (both inclusive). The cost of this operation is .
For example, let . A valid sequence of operations can be:
- Swap in with in to obtain .
- Swap in with in to obtain .
- Replace in with to obtain .
The cost of the above sequence of operations is .
Find whether we can convert the array to array using any (possibly zero) number of operations with cost .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers and , the size of array and the maximum cost of operations.
- The second line of each test case contains space-separated strings .
- The third line of each test case contains space-separated strings .
Output Format
For each test case, print YES if it is possible to convert array to using any (possibly zero) number of operations with cost . Else, print NO.
You may print each character of the string in uppercase or lowercase (for example, the strings yEs, yes, Yes, and YES will all be treated as identical).
Constraints
- and consist of characters from to (both inclusive).
- The sum of over all test cases won't exceed .
Sample 1:
3 2 2 1 9 9 1 2 2 1 11 11 1 4 1 22 13 12 89 28 98 21 31
YES NO YES
Explanation:
Test case : We can use one operation of type to swap in with in . Thus, becomes , which is equal to . We are able to do this with cost, which is .
Test case : It is impossible to convert to with at most cost.
Code Implementation:-
Chef and Adjacent Sums:
Problem Statement:-
You are given an array of size .
Consider an array of size formed by sorting in non-decreasing order.
Let .
Find whether there exists any rearrangement of the array , such that, for all ,
.
If such a rearrangement exists, print YES, otherwise print NO.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a integer — the number of elements in the array.
- The next line contains space-separated integers, denoting the elements of the array.
Output Format
For each test case, output YES, if a rearrangement exists that satisfies the conditions. Otherwise, output NO.
You may print each character in uppercase or lowercase. For example, NO, no, No, and nO are all considered the same.
Constraints
- The sum of over all test cases won't exceed .
Sample 1:
4 3 3 4 4 4 1 2 3 4 2 2 2 2 1 2
YES YES NO NO
Explanation:
Test case : Here and .
We can rearrange the array to such that and . Thus, the rearrangement is valid.
Test case : Here and .
We can rearrange the array to such that , , and . Thus, the rearrangement is valid.
Test case : The exists no possible rearrangement that satisfies the conditions.
Test case : The exists no possible rearrangement that satisfies the conditions.
Code Implementation:-
Max Count of 1:
Problem Statement:-
You are given a binary string of length .
You have to construct a binary string , of length , such that:
- For each , , where denotes the bitwise XOR operation;
- The count of s in the string is maximised.
Find the maximum count of in string .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- The first line of each test case contains a single integer , the length of the string .
- The second line of each test case contains a binary string .
Output Format
For each test case, output on a new line, the maximum count of in string .
Constraints
- consists of and only.
- The sum of over all test cases won't exceed .
Sample 1:
3 4 0011 4 1100 4 1010
3 3 2
Explanation:
Test case : Conside the string .
Here, , , . It can be shown that no other value of exists that satisfies the conditions and has more than three s.
Test case : Conside the string .
Here, , , . It can be shown that no other value of exists that satisfies the conditions and has more than three s.
Test case : The string , which has two s.
Code Implementation:-
Max Binary:
Problem Statement:-
Chef has a binary strings of length , and an integer .
Hitesh wants to maximize the decimal representation of using operations of the following type:
- Type : Insert at any position in the string.
- Type : Change any to .
Help Hitesh find the modified string with maximum possible decimal representation after performing at most operations.
Note that the decimal representation of a binary string refers to the numeric value it represents when converted to the decimal number system. For instance, the decimal representation of will be , and that of will be
Input Format
- First line will contain , number of test cases. Then the test cases follow.
- The first line of each test case contains two integers and .
- The second line contains the string .
Output Format
For each test case, output on a new line, the modified string with maximum possible decimal representation after performing at most operations.
Constraints
- consists of and only.
- The sum of and over all test cases won't exceed .
Sample 1:
4 4 2 1101 6 3 001110 5 4 00110 3 1 000
110100 10111000 10110000 100
Explanation:
Test case : We are allowed to perform two operations. We can perform both operations of type to obtain , having decimal value .
Test case : We are allowed to perform three operations. We can perform two operations of type to obtain , and one operation of type to obtain , having decimal value .
Code Implementation:-
Melt Gold:
Problem Statement:-
Chef has an ore with melting point of degrees.
Chef’s kiln has a initial temperature of degrees. The temperature of the kiln increases by degrees after the minute.
Find the minimum time in minutes after which the ore starts melting.
Note:
- We are only concerned about the temperature at the end of each minute and not during a minute.
- The ore starts melting if the temperature of the kiln becomes greater than or equal to the melting point.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two space-separated integers and — the melting point of the ore and the initial temperature of kiln.
Output Format
For each test case, output on a new line, the minimum time in minutes after which the ore starts melting.
Constraints
Sample 1:
3 3 2 5 3 10 5
1 2 3
Explanation:
Test case : The initial temperature of the kiln is and the melting point of ore is .
After first minute, the temperature of kiln increases by .
Thus, after minute the temperature of kiln becomes , which is equal to the melting point. Thus, the ore starts melting.
Test case : The initial temperature of the kiln is and the melting point of ore is .
After first minute, the temperature of kiln increases by , and becomes .
After second minute, the temperature of kiln increases by , and becomes .
Thus, after minutes the temperature of kiln becomes , which is greater than the melting point. Thus, the ore starts melting.
Test case : The initial temperature of the kiln is and the melting point of ore is .
After first minute, the temperature of kiln increases by , and becomes .
After second minute, the temperature of kiln increases by , and becomes .
After third minute, the temperature of kiln increases by , and becomes .
Thus, after minutes the temperature of kiln becomes , which is greater than the melting point. Thus, the ore starts melting.
Code Implementation:-
Elections in ChefLand:
Problem Statement:-
Election season has started in Chefland and the election commission wants to know the count of eligible voters.
There are people in Chefland where the age of the person in .
Given that a person needs to be at least years old to vote, find the number of eligible voters.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers and — the number of people in Chefland, and the minimum age required for a person to vote in Chefland.
- The next line contains space-separated integers, where the integer denotes the age of the person.
Output Format
For each test case, output on a new line, the number of eligible voters in Chefland.
Constraints
Sample 1:
4 4 3 5 3 1 2 3 2 1 3 4 4 2 2 1 2 4 5 6 1 2 3 4 5
2 2 3 0
Explanation:
Test case : The minimum age to vote in Chefland is years. There are people with age greater than equal to and thus, there are eligible voters.
Test case : The minimum age to vote in Chefland is years. There are people with age greater than equal to and thus, there are eligible voters.
Test case : The minimum age to vote in Chefland is years. There are people with age greater than equal to and thus, there are eligible voters.
Test case : The minimum age to vote in Chefland is years. There are no people with age greater than equal to and thus, there are no eligible voters.
Code Implementation:-


Comments
Post a Comment