Welcome To SDIBT ACM-ICPC Online Judge

VIRTUAL JUDGE Recent Contest F.A.Qs Discuss Home ProblemSet Status Ranklist Contest LoginRegister Exam
Problem 1068. -- Marbles

Marbles

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 1  Solved: 1
[Submit][Status][Discuss]

Description

I collect marbles (colorful small glass balls) and want to buy boxes to store them. The boxes come in two types: Type 1: each such box costs c1 dollars and can hold exactly n1 marbles Type 2: each such box costs c2 dollars and can hold exactly n2 marbles I want each box to be filled to its capacity, and also to minimize the total cost of buying them. Help me find the best way to distribute my marbles among the boxes.

Input

The input file may contain multiple test cases. Each test case begins with a line containing the integer n ( 1<=n<= 2,000,000,000). The second line contains c1 and n1, and the third line contains c2 and n2. Here, c1, c2, n1, and n2 are all positive integers having values smaller than 2,000,000,000. A test case containing a zero for the number of marbles terminates the input.

Output

For each test case in the input print a line containing the minimum cost solution (two nonnegative integers m1 and m2, where mi = number of type i boxes required if one exists. Otherwise print ``failed''. If a solution exists, you may assume that it is unique.

Sample Input

43
1 3
2 4
40
5 9
5 12
0

Sample Output

13 1
failed

HINT

Source

[Submit][Status][Discuss]

HOME Back

한국어 中文 English
All Copyright Reserved 2008-2010 SDIBT TEAM
GPL2.0 2003-2010 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin