An array scores of non‑negative integers is provided, together with an integer K. Two players, A and B, play a game that starts with A. On a player’s turn, they must select exactly K elements from the current array; if fewer than K elements remain, they select all of them. The sum of the selected elements is added to that player’s total, and the selected elements are removed. The game ends when the array is empty.
Player A always selects the K elements with the greatest numerical values. Player B always selects the K elements whose digit sum is largest (the digit sum of an integer is the total of its decimal digits). If two or more elements share the same digit sum, B chooses the ones with the largest numerical values among them.
Return the final total scores as [scoreA, scoreB].
Example 1:
Input: scores = [13, 24, 10, 9, 8, 7, 15, 6], K = 3
Output: [68, 24]
Explanation: A picks {24,15,13} (52), B picks {9,8,7} (24), A picks what remains {10,6} (16) → totals 68 and 24.
scores = [13,24, 10, 9, 8, 7, 15, 6] K = 3
[68,24]
| key | value |
|---|---|
| A | 0 |
| B | 0 |
Initial array: [13, 24, 10, 9, 8, 7, 15, 6]. K=3. A goes first.
Example 2:
Input: scores = [31, 40, 22, 13, 50], K = 2
Output: [103, 53]
Example 3:
Input: scores = [5, 3, 9, 1], K = 1
Output: [12, 6]
Constraints:
1 <= scores.length <= 20000 <= scores[i] <= 1000001 <= K <= scores.lengthscores = [13,24, 10, 9, 8, 7, 15, 6] K = 3
[68,24]
| key | value |
|---|---|
| A | 0 |
| B | 0 |
Initial array: [13, 24, 10, 9, 8, 7, 15, 6]. K=3. A goes first.