The Students' Council Breakfast
InterviewTime limit1sMemory limit128 MB
Given four ticket prices and a target amount, list every non-negative count combination that hits the target, count them, and report the fewest tickets needed.
- Level
Easy3 of 10
- Topics
- Brute force, Implementation, Math, Sorting
- Solved
- No attempts yet
Problem
The students' council at your school wants to organize a charity breakfast. Because older students are both wiser and better off, the council decides that each ticket's price depends on how many years the buyer has been at the school. A first-year student buys a PINK ticket, a second-year student a GREEN ticket, a third-year student a RED ticket, and a fourth-year student an ORANGE ticket.
Assume that every printed ticket is sold. The four ticket colours all have different prices.
Find every way to sell whole numbers of each coloured ticket so that the money raised is exactly the target amount. A combination is a tuple of non-negative integers (the number of PINK, GREEN, RED, and ORANGE tickets) that satisfies
At least one valid combination is guaranteed to exist.
Input
Enter the price of a PINK, GREEN, RED, and ORANGE ticket (in that exact order), followed by the exact amount of money to be raised by selling tickets. The five values are positive integers, each on its own line.
Output
Print every combination that raises exactly the target amount, one per line, in ascending lexicographic order of the counts — that is, sorted by the number of PINK tickets first, then GREEN, then RED, then ORANGE. Use the format
# of PINK is p # of GREEN is g # of RED is r # of ORANGE is o
Then, on its own line, print the total number of combinations found as Total combinations is N.
Finally, print the fewest tickets needed to raise the target amount — the minimum value of over all valid combinations — as Minimum number of tickets to print is M.