Skip to main content

Posts

Showing posts with the label CodeChef SnackDown 2021

Equal Beauty CodeChef SnackDown 2021 Round 1A

 Equal Beauty CodeChef SnackDown 2021 Round 1A Question The beauty of an (non-empty) array of integers is defined as the difference between its largest and smallest element. For example, the beauty of the array [2,3,4,4,6] is 6−2=4. An array A is said to be good if it is possible to partition the elements of A into two non-empty arrays B1 and B2 such that B1 and B2 have the same beauty. Each element of array A should be in exactly one array: either in B1 or in B2. For example, the array [6,2,4,4,4] is good because its elements can be partitioned into two arrays B1=[6,4,4] and B2=[2,4], where both B1 and B2 have the same beauty (6−4=4−2=2). You are given an array A of length N. In one move you can: Select an index i (1≤i≤N) and either increase Ai by 1 or decrease Ai by 1. Find the minimum number of moves required to make the array A good. Input Format The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow. Each ...

Equal Beauty CodeChef SnackDown 2021 Round 1A

 Equal Beauty CodeChef SnackDown 2021 Round 1A Question The beauty of an (non-empty) array of integers is defined as the difference between its largest and smallest element. For example, the beauty of the array [2,3,4,4,6] is 6−2=4. An array A is said to be good if it is possible to partition the elements of A into two non-empty arrays B1 and B2 such that B1 and B2 have the same beauty. Each element of array A should be in exactly one array: either in B1 or in B2. For example, the array [6,2,4,4,4] is good because its elements can be partitioned into two arrays B1=[6,4,4] and B2=[2,4], where both B1 and B2 have the same beauty (6−4=4−2=2). You are given an array A of length N. In one move you can: Select an index i (1≤i≤N) and either increase Ai by 1 or decrease Ai by 1. Find the minimum number of moves required to make the array A good. Input Format The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow. Each ...

Round Robin Ranks CodeChef SnackDown 2021 Round 1A

 Round Robin Ranks CodeChef SnackDown 2021 Round 1A Question A round-robin tournament is being held in Chefland among N teams numbered 1,2,...,N. Every team play with all other teams exactly once. All games have only two possible results - win or loss. A win yields 2 points to the winning team while a loss yields no points. What is the maximum number of points a team finishing at the Kth position can score? Note: If two teams have the same points then the team with the higher team number achieves the better rank. Input Format First line will contain T, number of testcases. Then the testcases follow. Each testcase contains a single line of input, two space-separated integers N,K. Output Format For each testcase, output in a single line an integer - the maximum points the team ranked K in the round-robin tournament can score. Constraints 1≤T≤10^5 1≤K≤N≤10^9 Sample Input 1  3 3 3 4 1 7 4 Sample Output 1  2 6 8 Explanation Test Case 1: There are 3 teams in the tournament. The...

Min Max LCM CodeChef SnackDown 2021 Round 1A Solution

 Min Max LCM CodeChef SnackDown 2021 Round 1A Solution Question You are given two positive integers X and K. You have to output the minimum and maximum value of LCM(i,j) where X≤i<j≤X⋅K. We define LCM(i,j) for two positive integers i and j as the minimum positive integer y such that both i and j divide y without remainder. Input Format First line will contain T, number of testcases. Then the testcases follow. Each testcase contains of a single line of input, two space separated integers X and K. Output Format For each testcase, output two space separated integers - the minimum and maximum possible value respectively of LCM(i,j) where X≤i<j≤X⋅K. Constraints 1≤T≤10^5 1≤X≤10^8 2≤K≤10^8 It is guaranteed that, for each test case, X⋅K≤10^9 Sample Input 1  2 4 3 2 3 Sample Output 1  8 132 4 30 Explanation Test Case 1: We want to find the minimum and maximum value of LCM(i,j) for 4≤i<j≤12. It is easy to verify that the LCM(4,8)=8 is the minimum possible value whereas LCM...

Dance Moves CodeChef SnackDown 2021 Round 1A Solution

 Dance Moves CodeChef SnackDown 2021 Round 1A Solution Question This year Chef is participating in a Dancing competition. The dance performance will be done on a linear stage marked with integral positions. Initially, Chef is present at position X and Chef's dance partner is at position Y. Chef can perform two kinds of dance moves. If Chef is currently at position k, Chef can: Moonwalk to position k+2, or Slide to position k−1 Chef wants to find the minimum number of moves required to reach his partner. Can you help him find this number? Input Format First line will contain a single integer T, the number of testcases. Then the description of T testcases follows. Each testcase contains a single line with two space-separated integers X,Y, representing the initial positions of Chef and his dance partner, respectively. Output Format For each testcase, print in a separate line, a single integer, the minimum number of moves required by Chef to reach his dance partner. Constraints 1≤T≤10^...

Yet Another SubSegment Sum Problem CodeChef SnackDown 2021 Advanced Practice Contest

 Yet Another SubSegment Sum Problem CodeChef SnackDown 2021 Advanced Practice Contest  Question You are given two arrays  A  and  B , each consisting of  N  integers. You are also given  M  queries of the form  L j  R j  C j  D j . For each of these queries, we ask you to calculate the value of the  sum  of  max{0, A i  × C j  - B i  × D j }  over  i  from  L j  to  R j . This is an on-line problem, so you won't get the next query unless you answer the current one. Input The first line of the input contains an integer  N  denoting the length of the arrays  A  and  B . The second line contains  N  space-separeted integer numbers, denoting the array  A . The third line contains  N  space-separated integer numbers, denoting the array  B . The fourth line contains an integer  Q  denoting the number of qu...

Floor Division Game CodeChef SnackDown 2021 Advanced Practice Contest

Floor Division Game CodeChef SnackDown 2021 Advanced Practice Contest Question Henry and Derek are waiting on a room, eager to join the Snackdown 2016 Qualifier Round. They decide to pass the time by playing a game. In this game's setup, they write  N  positive integers on a blackboard. Then the players take turns, starting with Henry. In a turn, a player selects one of the integers, divides it by 2, 3, 4, 5 or 6, and then takes the  floor  to make it an integer again. If the integer becomes 0, it is erased from the board. The player who makes the last move wins. Henry and Derek are very competitive, so aside from wanting to win Snackdown, they also want to win this game. Assuming they play with the optimal strategy, your task is to predict who wins the game. Input The first line of the input contains an integer  T  denoting the number of test cases. The description of  T  test cases follows. The first line of each test case contains a single inte...

Robot Walk CodeChef SnackDown 2021 Solution

Robot Walk CodeChef SnackDown 2021 Solution Question Chef has recently learned robotics and has now been able to construct a robot that's much better than his  robots from last year . It's still somewhat limited, but it's definitely more flexible than before. Here are its properties: The robot can only move forward towards the direction it faces, and can only face either horizontally or vertically. The robot can only turn at 90 degree angles. The robot is designed to turn  exactly N times . In addition, this robot is programmable. You can feed it  2N+1  values:  a 0 ,  f 1 ,  a 1 ,  f 2 ,  a 2 , ...,  f N ,  a N , where each  a i  is a positive integer and each  f i  is either  L  or  R , and then it will perform the following actions: Initially face north. Move forward by  a 0  steps. If  f 1  is  L , turn left 90 degrees; if  f 1  is  R , turn right 90 degr...

Lighting Rectangle CodeChef SnackDown 2021 Advance Practice Contest

 Lighting Rectangle CodeChef SnackDown 2021 Advance Practice Contest Question You are given an axis-aligned rectangle in a 2D Cartesian plane. The bottom left corner of this rectangle has coordinates  ( 0 , 0 )  and the top right corner has coordinates  ( N − 1 , N − 1 ) . You are also given  K  light sources; each light source is a point inside or on the perimeter of the rectangle. For each light source, let's divide the plane into four quadrants by a horizontal and a vertical line passing through this light source. The light source can only illuminate one of these quadrants (including its border, i.e. the point containing the light source and two half-lines), but the quadrants illuminated by different light sources may be different. You want to assign a quadrant to each light source in such a way that when they illuminate their respective quadrants, the entire rectangle (including its perimeter) is illuminated. Find out whether it is possible to assign qu...