RescueProblem code: DCE04 |
The Titanic ship is sinking. The nearest ship has answered the SOS call, and come to rescue the people. Everyone is anxious to get to safety. Unfortunately, the new ship may not have enough room to take everyone to safe land. This adds to the anxiety of people.
To avoid stampede, there has to be some rescue plan. You are made incharge of this. You have to make sure that as many people are safe as possible. Given the capacity of the ship, that is, the number of people that can board the ship, you have to calculate how many men, women and children can be sent to safety.
The following rules apply:
* The foremost priority is safety for children, but there must be atleast one adult (a man or a woman) for every four children sent to the rescue ship. For upto four children, one adult, for five to eight children, 2 adults, and so on.
* Next priority is for women, but there must be at least one man for every two women. For upto two women, one man, for three to four women, two men, and so on.
Input
First line contains the number of test cases (t less than 10000)
The next t lines contain four integers (each between 1 to 10000 inclusive) each separated by a single space.
The integers represent the capacity of the rescue ship, number of men on TITANIC, number of women and number of children, in this order.
Output
Display t lines, each line has three space separated integers denoting the number of men, women and children put to safety, in this order.
Example
Input: 3 17 5 10 19 18 2 6 10 20 5 2 23 Output: 2 2 13 2 4 10 2 2 16 Explanation: Explanation for case 2: Since only 2 men are present, the number of women can not be more than 4.
| Author: | uploader0 |
| Date Added: | 14-10-2009 |
| Time Limit: | 8 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments

Fetching successful submissions

can any one put some more
can any one put some more input and their output(worst case)?
Heres 1 more test
Heres 1 more test case:
Input:
2
100 10 2 200
100 2 10 30
Output:
10 2 48
2 4 24
Heres 1 more test
Heres 1 more test case:
Input:
2
100 10 2 200
100 2 10 30
Output:
10 2 48
2 4 24
@Sailesh Mittal: In d prblm
@Sailesh Mittal: In d prblm stmnt, it has ben mntioned dat,
"Next priority is for women, but there must be at least one man for every two women. For upto two women, one man, for three to four women, two men, and so on.
"
Den, hw com d o/p of 1st & 2nd test cases r
2 men and 2 women?
I cannot not say if it is wrong, but I need explaination.
Sory, 1st & 3rd cases...
Sory, 1st & 3rd cases...
@ Pathak plz look at the
@ Pathak
plz look at the capacity too. You have to make out the rest of it.
Good Luck!