Beautiful Subsequence solution codechef

Beautiful Subsequence solution codechef An array AA consisting of NN integers is called KK-beautiful if it holds the following property: The number of adjacent indices with different values is at most KK. More formally, there are at most KK indices ii (1≤i<N1≤i<N) such that Ai≠Ai+1Ai≠Ai+1. Note that according to this definition, if an array AA is KK-beautiful, then AA is also (K+1)(K+1)-beautiful. You are given an array AA consisting of NN integers and an integer KK. Find the length of the longest KK-beautiful subsequence … Read more

Mod Equality solution codechef

Mod Equality solution codechef You are given NN non-negative integers A1,A2,…,ANA1,A2,…,AN. You are allowed to perform following operation any number of times: Choose any valid index ii (1≤i≤N1≤i≤N) and a positive integer M>0M>0 and replace AiAi with AimodMAimodM. That is, replace AiAi with its remainder when divided by MM, which is a value between 00 and M−1M−1, inclusive. MM does not need to be same between different operations. Find the minimum number of operations to make all … Read more

Chef In Infinite Plane solution codechef

Chef In Infinite Plane solution codechef Chef has an integer sequence A1,A2,…,ANA1,A2,…,AN. For each index ii (1≤i≤N1≤i≤N), Chef needs to divide AiAi into two positive integers xx and yy such that x+y=Aix+y=Ai, then place this as a point (x,y)(x,y) in the infinite 22-dimensional coordinate plane. Help Chef to find the maximum number of distinct points that can be put in the plane, if he optimally splits the values AiAi. Note that Chef can only … Read more