#B4056. Cowboy Card Duel
Cowboy Card Duel
Cowboy Card Duel
In the wild west, a young cowboy named Little Z starts with (x) gold coins and wishes to buy cards from a merchant in order to duel his cowboy friends. Each card is sold at a cost equal to its denomination, and the available denominations are (1, 2, 3, 4,) and (5).
The merchant offers (n) card packs, each containing 5 cards. For every pack, Little Z examines the five cards and purchases at most one card—the one with the highest denomination that he can afford at that moment. He pays coins equal to the card’s value. If he cannot afford any card in a pack, he skips that pack.
After processing all (n) packs, Little Z is left wondering how many cards of each denomination he has bought and how many coins remain. Your task is to simulate his shopping spree and output the final number of coins left and the count of purchased cards for each denomination (from (1) to (5)).
inputFormat
The first line contains two integers (x) and (n) ((1 \leq x \leq 10^9), (1 \leq n \leq 10^5)), representing the initial coins and the number of card packs respectively. This is followed by (n) lines, each containing 5 integers that represent the denominations of the cards in that pack.
outputFormat
Output two lines:
- The first line should contain the remaining number of coins after the purchasing process.
- The second line should contain 5 space-separated integers where the (i)-th integer represents the number of cards with denomination (i) that Little Z purchased.
sample
10 2
1 2 3 4 5
1 2 3 4 5
0
0 0 0 0 2
</p>