Question: we have an array (a) of (n) elements we choose some pairs from the array such that the sum of beauty is maximum beauty of
we have an array (a) of (n) elements we choose some pairs from the array such that the sum of beauty is maximum beauty of pair(a, b) = abs(a - b) abs : abslute value abs(3 - 5) = 2 abs (7 - 5) = 2 ex. : a = {1, 2, 10, 10} if we choose pairs as : (1, 10), (2, 10) the sum of beauty = abs(1 - 10) + abs(2 - 10) = 9 + 8 = 17 Input Format int n : size of array (a) In the second line the sequence of n integers a1, a2, ..., an (1 ai 10^9) is given, where ai is the ith number in array Constraints 2 <= n <= 100000(n always even(n % 2 = 0)) 1 <= ai <= 100000 Output Format maximum sum of beauty Sample Input 0 4 1 2 10 10 Sample Output 0 17
pleeeeease now in c++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
