ratings; there is an even number of players, and each one goes into exactly one pair.
A team plays at the level of its weaker member, so a pair's strength is the smaller of its two ratings. Split the players into pairs so that the total strength of all pairs is as large as possible, and return that total.ratings=[7, 2, 5, 1] → 6
The best split is (1, 2) and (5, 7): team strengths 1 and 5, total 6. Pairing (1, 7) and (2, 5) would give only 1 + 2 = 3.
ratings=[-3, 4, 4, 0, -3, 9] → 1
Pairs (-3, -3), (0, 4), (4, 9) give -3 + 0 + 4 = 1.
ratings ≤ 2·10⁴, and the length is evenratings[i] ≤ 10⁴ratings=[7, 2, 5, 1]
6
Run checks the first 3 tests in your browser. Submit checks all 110 tests on the server, hidden ones included.