TopCoder problem "MixingLiquids" used in SRM 355 (Division I Level One , Division II Level Three)



Problem Statement

    

In Chemistry, there's a different meaning to the word 'solution' than in programming. When we mix x liters of some substance with (100-x) liters of water, we get 100 liters of x-% solution of that substance.

You are given several bottles containing solutions of the same substance. The i-th bottle contains amount[i] liters of percent[i]-% solution. Return the maximal number of liters of need-% solution we can get by pouring together some of these bottles (possibly partially, see example 0).

 

Definition

    
Class:MixingLiquids
Method:howMuch
Parameters:int[], int[], int
Returns:double
Method signature:double howMuch(int[] percent, int[] amount, int need)
(be sure your method is public)
    
 

Notes

-The returned value must have an absolute or relative error less than 1e-9.
 

Constraints

-percent will contain between 1 and 50 elements, inclusive.
-Each element of percent will be between 0 and 100, inclusive.
-amount will contain the same number of elements as percent.
-Each element of amount will be between 1 and 1000, inclusive.
-need will be between 0 and 100, inclusive.
 

Examples

0)
    
{0, 100}
{20, 30}
50
Returns: 40.0
We have 20 liters of water and 30 liters of pure substance. We need a 50% solution, so we combine all the water with 20 liters of substance.
1)
    
{0, 100}
{20, 30}
60
Returns: 50.0
We can use everything we have.
2)
    
{90, 70, 80}
{10, 10, 10}
50
Returns: 0.0
All our bottles contain too much substance.
3)
    
{30, 80, 60}
{40, 10, 15}
57
Returns: 35.18518518518519
4)
    
{50,50,50}
{395,971,964}
50
Returns: 2330.0

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7886

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10712&pm=7886

Writer:

Petr

Testers:

PabloGilberto , brett1479 , Olexiy , marian

Problem categories:

Sorting