#K7196. Taco Score Game
Taco Score Game
Taco Score Game
You are given a series of test cases. For each test case, you are provided with a sequence of integers. Two players, John and Jane, take turns selecting a number from either end of the sequence. On each turn, the player picks the larger of the two available numbers. In case both numbers are equal, the player picks the rightmost number. The chosen number is added to the player's score, and the number is removed from the sequence. The game continues until there are no numbers left.
Formally, let \(N\) be the length of the sequence and \(a_0, a_1, \ldots, a_{N-1}\) be the sequence. John starts the game. At each move, if \(a_{left} > a_{right}\), the current player picks \(a_{left}\); otherwise, the player picks \(a_{right}\). The game stops when \(left > right\). Output the final scores of John and Jane for each test case.
Input Constraints:
- T (number of test cases) is a positive integer.
- For each test case, the first number is \(N\), followed by \(N\) integers representing the sequence.
Note: Read input from stdin
and write output to stdout
.
inputFormat
The input begins with an integer \(T\) representing the number of test cases. For each test case, the first line contains an integer \(N\), the number of elements in the sequence, followed by a line containing \(N\) space-separated integers.
Example:
1 5 1 2 3 4 5
outputFormat
For each test case, output a single line containing two space-separated integers representing the final scores of John and Jane respectively.
Example:
9 6## sample
1
5
1 2 3 4 5
9 6
</p>