Clash Royale (Small)
Time limit5sMemory limit512 MB
Spend up to M coins upgrading N cards, then pick 8 cards to maximize the deck's total attack power.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Sorting
- Solved
- No attempts yet
Problem
Clash Royale is a real-time strategy card game. Each card has an attack power and a level. Each player picks 8 cards to form a battle deck, and the total attack power of a deck is the sum of the attack powers of its cards. Players fight each other by placing cards from their battle decks into the arena. The winner of a battle receives coins, which can be used to upgrade cards. Upgrading a card increases its attack power.
After days of arena fighting, Shawn has collected a total of coins and has decided to upgrade some of his cards. Shawn has cards. The -th card can be at any level from through , and its attack power at level is . A card is upgraded one level at a time, and raising the -th card from level to level costs coins. Before any upgrade, the -th card is at level .
Shawn wants to spend some or all of his coins on upgrades and then form a deck of exactly 8 cards whose total attack power is as large as possible. Help him do this. He can upgrade the same card more than once as long as he can afford it, and he does not have to upgrade every card.
Input
The first line contains the number of test cases . test cases follow.
Each test case starts with a line containing and , the number of coins and the number of cards Shawn has. Then blocks follow, and the -th block consists of 3 lines describing the -th card.
- The first line contains and , the maximum level and the current level of the card.
- The second line contains integers , the attack power at each level.
- The third line contains integers , the number of coins needed to upgrade the card when it is at level . If , this line is empty.
Output
For each test case, print one line Case #x: y, where is the test case number (starting from 1) and is the maximum total attack power of a deck that Shawn can form with the coins he has.
Constraints
Hint
In the first sample test case, you can upgrade the first 4 cards to level 3, upgrade the 5th and 6th cards to level 2, and keep the last 2 cards at level 1. This costs coins, and the total attack power is , which is the maximum possible.
In the second sample test case, Shawn has 10 cards, so he picks 8 of them for the deck.