436. Array Partition (Max Sum of Pair Minimums)
EasySortingGreedy
Group the 2k numbers into k pairs to maximise the sum of the smaller number in each pair. Print that sum.
Input format
Line 1: n (even) Line 2: n integers
Output format
The maximum sum.
Example 1
Input
4 1 4 3 2
Output
4
Example 2
Input
6 6 2 6 5 1 2
Output
9
Constraints
2 ≤ n ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…