In short, the sum of all number is fixed, to maximize the sum of smaller group, you want to minimize the diff of the sum of 2 groups.

And the best way to do that is to pair the numbers that are next to each other in sorted order.

**C++**

```
class Solution {
public:
int arrayPairSum(vector<int>& nums) {
int sum = 0;
sort(nums.begin(), nums.end());
for (int i = 0; i < nums.size(); i += 2) {
sum += nums[i];
}
return sum;
}
};
```

**Java**

```
class Solution {
public int arrayPairSum(int[] nums) {
int sum = 0;
Arrays.sort(nums);
for (int i = 0; i < nums.length; i += 2) {
sum += nums[i];
}
return sum;
}
}
```