TopcoderArchiveVisit Topcoder
SRM20 Jun 2007
SRM 355

MixingLiquids

Problem statement, definition, constraints, and public examples.

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

  1. {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.
  2. {0, 100}
    {20, 30}
    60
    Returns: 50.0
    We can use everything we have.
  3. {90, 70, 80}
    {10, 10, 10}
    50
    Returns: 0.0
    All our bottles contain too much substance.
  4. {30, 80, 60}
    {40, 10, 15}
    57
    Returns: 35.18518518518519
  5. {50,50,50}
    {395,971,964}
    50
    Returns: 2330.0
Back to all problems