The Production Manager

All submissions for this problem are available.
Production Manager of a biscuit manufacturing company “Ban2g Pvt. Ltd.” needs a solution. The biscuits are manufactured just on time and are ready to be delivered to a Japanese store. But just a day before the delivery, the company who had taken the contract of packaging the biscuits, changes the cost of all its delivery boxes.
Ban2g Pvt. Ltd. wants to buy boxes which are available in two types, first one costs c1 and can hold n1 biscuits and the second one costs c2 and can hold n2 biscuits. Each box has to be filled to its capacity. You have to find the best way to distribute the biscuits such that total cost is minimized.
Input
The first line specifies the number of test cases. For each test case, the first line of input specifies the total number of biscuits to be packed. (numbered 1 to 300,000,000). The next line contains c1, n1, c2, n2.
Output
For each test case in the input, print a line containing the minimum cost solution i.e. three nonnegative integers m1, m2 and minimum cost (mi = number of type ‘i’ boxes required if one exists).
Otherwise print 0 0 0.
Example
Input: 2 78 10 15 1 8 37 10 9 9 8 Output: 2 6 26 0 0 0 Explanation In the 1st test case, no of biscuits to be packed is 78. The output is “2 6 26” (“2” boxes of size 15, “6” boxes of size 8 and hence the cost is “26”)
Author:  rishi_agarwal 
Tags  rishi_agarwal 
Date Added:  15022012 
Time Limit:  50 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 
Can you provide some more