Undercut
Time limit1sMemory limit128 MB
Add up both players' scores across card rounds where the higher card scores unless the lower card is exactly one less.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Undercut is a game for two players, each holding five cards numbered through . In every round both players secretly choose one of their cards and then reveal them at the same time. Scoring works like this. The player with the higher card scores the value of that card, unless the other card is exactly one less. In that case the player with the lower card scores the sum of the two cards, which is called an undercut. If both players reveal the same card, nobody scores. For example, if Tessa plays a and Danny plays a , Tessa scores points, but if Tessa plays a and Danny plays a instead, Danny scores points.
Undercut is a fine mental game, because each side keeps second-guessing: they think I will play a , so they will play a , so I will play a and undercut them, but they will expect that and play a , so I will just play a , and then they will think... This problem does not model that reasoning. You are given the cards both players actually revealed and you have to work out the final score. One rule changes: undercutting a with a scores points instead of , which in the real game makes the worth playing.
Input
The first line contains an integer , the number of test cases.
Each test case starts with a line containing a positive integer with , the number of rounds in that game. After it come integers on one or more lines. Taking them two at a time gives the cards played in each round: the first two numbers are the cards Tessa and Danny played in the first round, the next two are their cards in the second round, and so on. Every card value is between and , inclusive.
Output
For each test case, print Tessa's and Danny's final scores on one line in this format.
Game k: Tessa a Danny b
Here is the test case number starting from , is Tessa's score, and is Danny's score.