Balatro
Time limit12sMemory limit1024 MB
Pick a subsequence of add and multiply cards, using at most k multiply cards, to maximize the final score for each length up to n.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Greedy, Math
- Solved
- No attempts yet
Problem
Cards are arranged in a row. Each card has a value and is one of two types: an add card (a) or a multiply card (m).
The score is computed as follows. The initial score is 0. Process the cards from left to right.
- If the card is an add card, increase the score by the card's value.
- If the card is a multiply card, multiply the score by the card's value.
The final score is the score after all cards are processed.
For each subsequence size, find the maximum score you can get from a subsequence of that size. If the limit on multiply cards makes that size impossible, find the maximum score for the largest possible size below it. The chosen cards keep their original order, and you cannot rearrange them. A subsequence does not have to be contiguous.
Input
The first line contains two integers () and (), where is the number of cards and is the maximum number of multiply cards you can use.
Each of the next lines contains a letter and an integer . is either a (add card) or m (multiply card), and is the card's value ().
The product of all multiply card values is at most .
Output
Output lines. The -th line contains the maximum score for a subsequence of length at most , for from 1 to .