Problems > Best Pairing

Best Pairing

Difficulty: 1400 3000 ms 128 MB

greedy sorting

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.