Writing Numbers on Paper
Time limit1sMemory limit128 MB
Given a target average P (with up to 9 decimal digits) find the fewest sheets, each labeled 1 to 5, whose numbers average exactly P, and print the count of each value used.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Greedy
- Solved
- No attempts yet
Problem
Each sheet of paper can contain exactly one integer from 1 to 5, and there are as many sheets as needed.
Choose some sheets and write numbers on them so that the average of all written numbers is exactly P. Among all valid choices, use as few sheets as possible.
Given P, output how many times to write each of the numbers 1, 2, 3, 4, and 5.
Input
The first line contains P. P is at least 1 and at most 5, and it is written with 1 to 9 digits after the decimal point.
Output
Print five nonnegative integers on one line, separated by spaces. The first is the count of 1s, the second is the count of 2s, and so on through the count of 5s. If more than one answer is possible, print any one of them.