Pseudominion (Small)
Time limit5sMemory limit512 MB
Choose the order to play hand and deck cards so draws and extra turns produce the largest total score before turns run out.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Simulation
- Solved
- No attempts yet
Problem
You are playing a card game. Every card carries three bonus numbers: a card bonus , a score bonus , and a turn bonus . Some cards start in your hand and the rest sit in a deck on the table. You start with 1 turn left and a score of 0.
On a turn you may pick any card from your hand and play it. If the card has bonus numbers , , , the following happens in order.
- The card is discarded from your hand and can never be used again.
- You draw the top cards of the deck into your hand. If the deck holds fewer than cards, you draw all of them.
- Your score increases by .
- Your number of remaining turns increases by .
Playing a card first spends 1 turn and then adds turns. If your hand is empty at the start of a turn, nothing happens on that turn. Once no turns remain, you cannot play another card. Report the largest score you can reach before running out of turns.
The walkthrough below shows how the rules interact. It uses a value larger than the limits allow.
The table below traces a score of 8 from these cards. The first three columns give your hand, your remaining turns, and your score just before each play, and the last column gives the card you play on that turn.
Card bonuses and turn bonuses let you chain a long run of cards together before you have to stop.
Input
The first line of the input gives the number of test cases, . test cases follow.
Each test case begins with a line containing , the number of cards in your hand. The next lines each contain three integers , , and , the bonus numbers of one card in your hand.
The next line contains , the number of cards in the deck. The next lines each contain three integers , , and , the bonus numbers of one card in the deck. The deck cards are listed in the order you draw them.
Limits
Output
For each test case, output one line containing Case #x: S, where is the test case number starting from 1 and is the largest score you can obtain before running out of turns.