Best Pairing
N is even. Split the values into N/2 pairs so that the sum of the pair products is as large as possible. Print that maximum.
Input: the first line has N (even); the second line has N integers.
Output: the maximum possible sum of pair products.
Constraints:
- 2 ≤ N ≤ 105
- −100 ≤ ai ≤ 100
Sample Tests
Input 1
4 1 2 3 4
Output 1
14
Input 2
4 -3 -4 1 2
Output 2
14
Discussion (opens after you solve — no spoilers before)
No comments yet.