Under construction

Still being built. Things may change

The Students' Council Breakfast

Interview

Time limit1sMemory limit128 MB

Summary
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 p,g,r,op, g, r, o (the number of PINK, GREEN, RED, and ORANGE tickets) that satisfies

p×PINK+g×GREEN+r×RED+o×ORANGE=target amount.p \times \text{PINK} + g \times \text{GREEN} + r \times \text{RED} + o \times \text{ORANGE} = \text{target amount}.

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 (p,g,r,o)(p, g, r, o) — 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 p+g+r+op + g + r + o over all valid combinations — as Minimum number of tickets to print is M.

Examples1

  1. Example 1

    Input
    1
    2
    3
    4
    3
    
    Expected output
    # of PINK is 0 # of GREEN is 0 # of RED is 1 # of ORANGE is 0
    # of PINK is 1 # of GREEN is 1 # of RED is 0 # of ORANGE is 0
    # of PINK is 3 # of GREEN is 0 # of RED is 0 # of ORANGE is 0
    Total combinations is 3.
    Minimum number of tickets to print is 1.