Skip to main content

Posts

Showing posts from September, 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 test

Show maximum number of edges in a simple or regular graph of n vertices is n(n-1)/2

 Show maximum number of edges in a simple or regular graph of n vertices is n(n-1)/2   There are two ways in which you can solve it one is manually and the other by induction. Though induction is the preferred way of doing it so lets see the solution by the use of induction. If we consider 3 vertices are present then by the formula n (n - 1) / 2 where n is the number of vertices we see 3 ( 3 - 1) / 2 = 3 For n = 3 the formula is proved then for n = k it will also be true. According to mathematical induction if we consider n = k + 1 by the formula we see  (k + 1)(k + 1 - 1) / 2 = k( k + 1)/2   -----------> Equation(1) For k vertices, number of edges = k ( k - 1) / 2    If we add one extra vertex then total number of vertices will be ( k + 1) then the total number of edges after adding one edge will be  (k ( k - 1) / 2)  +  k k ( k + 1) / 2  -------------> Equation(2) So equation(1) = equation(2) so our theorem is proved. Thus the maximum number of edges in a simple graph of n vert

Codeforces Round 745 Div 2 Editorial Solutions A-C

 Codeforces Round 745 Div 2 Editorial Solutions A-C CQXYM Count Permutations CQXYM is counting permutations length of  2 n A permutation is an array consisting of  n  distinct integers from  1  to  n  in arbitrary order. For example,  [ 2 , 3 , 1 , 5 , 4 ]  is a permutation, but  [ 1 , 2 , 2 ]  is not a permutation ( 2  appears twice in the array) and  [ 1 , 3 , 4 ]  is also not a permutation ( n = 3  but there is  4  in the array). A permutation  p (length of  2 n ) will be counted only if the number of  i  satisfying  p i < p i + 1  is no less than  n . For example: Permutation  [ 1 , 2 , 3 , 4 ]  will count, because the number of such  i i  that  p i < p i + 1  equals  3  ( i = 1 ,  i = 2 ,  i = 3 ). Permutation  [ 3 , 2 , 1 , 4 ]  won't count, because the number of such  i i  that  p i < p i + 1  equals  1  ( i = 3 ). CQXYM wants you to help him to count the number of such permutations modulo  1000000007  ( 10 9 + 7 ). In addition,  modulo operation  is to get the rema