Skip to main content

Posts

Showing posts with the label programming

Maximise Function codechef February 2021 long challenge editorial

 Maximize Function codechef February 2021  long challenge editorial - Problem Statement-  You are given a sequence  A 1 , A 2 , … , A N A 1 , A 2 , … , A N . Find the maximum value of the expression  | A x − A y | + | A y − A z | + | A z − A x | | A x − A y | + | A y − A z | + | A z − A x |  over all triples of pairwise distinct valid indices  ( x , y , z ) ( x , y , z ) . Input The first line of the input contains a single integer  T T  denoting the number of test cases. The description of  T T  test cases follows. The first line of each test case contains a single integer  N N . The second line contains  N N  space-separated integers  A 1 , A 2 , … , A N A 1 , A 2 , … , A N . Output For each test case, print a single line containing one integer ― the maximum value of  | A x − A y | + | A y − A z | + | A z − A x | | A x − A y | + | A y − A z | + | A z − A x | . Constraints 1 ≤ T ≤ 5 1 ≤ T ≤ 5 3 ≤ N ≤ 10 5 3 ≤ N ≤ 10 5 | A i | ≤ 10 9 | A i | ≤ 10 9  for each valid  i i Subtasks Sub