Pair sum (Contest)
Pair sum (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Pair sum (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
Given an array Arr, of N integers find the sum of max(A[i], A[j]) for all i, j such that i < j. Input The first line of the input contains an integer N, the size of the array. The second line of the input contains N integers, the elements of the array Arr.
Constraints: 1 <= N <= 100000 1 <= Arr[i] <= 100000000 Output Print a single integer which is the sum of min(A[i], A[j]) for all i, j such that i < j. Example Sample Input 1 4 5 3 3 1
Sample Output 1 24
Sample Input 2 2 1 10
Sample Output 2 10
Explanation 1 max(5,3) + max(5,3) + max(5,1) + max(3,3) + max(3,1) + max(3,1) = 24
link: