eolymp
bolt
Try our new interface for solving problems
Problems

Marbles

Marbles

I have some (say, \textbf{n}) marbles (small glass balls) and I am going to buy some boxes to store them. The boxes are of two types: \textit{Type} \textbf{1}: each box costs \textbf{c_1} Taka and can hold exactly \textbf{n_1} marbles \textit{Type} \textbf{2}: each box costs \textbf{c_2} Taka and can hold exactly \textbf{n_2} marbles I want each of the used boxes to be filled to its capacity and also to minimize the total cost of buying them. Since I find it difficult for me to figure out how to distribute my marbles among the boxes, I seek your help. I want your program to be efficient also. \InputFile The input file may contain multiple test cases. Each test case begins with a line containing the integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{2000000000}). The second line contains \textbf{c_1} and \textbf{n_1}, and the third line contains \textbf{c_2} and \textbf{n_2}. Here, \textbf{c_1}, \textbf{c_2}, \textbf{n_1} and \textbf{n_2} are all positive integers having values smaller than \textbf{2000000000}. A test case containing a zero for \textbf{n} in the first line terminates the input. \OutputFile For each test case in the input print a line containing the minimum cost solution (two nonnegative integers \textbf{m_1} and \textbf{m_2}, where \textbf{m_i} = number of \textbf{Type i} boxes required) if one exists, print "\textbf{failed}" otherwise. If a solution exists, you may assume that it is unique.
Time limit 1 second
Memory limit 64 MiB
Input example #1
43
1 3
2 4
40
5 9
5 12
0
Output example #1
13 1
failed