Statistics

Problem Statement for "WaterLevel"

Problem Statement

The lake where we vacation sometimes floods. As soon as the level reaches the maximum level that can be contained by the banks of the lake, the additional water covers a fixed floodplain area, which enlarges the area of the lake. Below are views of the lake from the side, with water indicated by X's.
   |              |          |              |
   |___        ___|          |XXXXXXXXXXXXXX|
       |      |                  |XXXXXX|
       |      |                  |XXXXXX|
       |XXXXXX|                  |XXXXXX|
       |XXXXXX|                  |XXXXXX|

       (not flooded)             (flooded)

The amount of evaporation depends on the surface area. When the lake is not flooded, the evaporation is evapNormal units of water per day. When the lake is flooded, the evaporation is evapFlood units per day. The lake never goes dry and never extends beyond the floodplain.

Assume that the lake is initially full but not flooded. Create a class WaterLevel that contains a method netAmt that is given evapNormal, evapFlood, and int[] rain, the amounts of rain that fell on each day during our vacation. The method returns the net increase (a positive value) or decrease (a negative value) in the units of water in the lake during our vacation. The i-th element of rain tells how many units of water fell during the entire i-th day. You should assume that it rains at a constant rate throughout the day.

Definition

Class:
WaterLevel
Method:
netAmt
Parameters:
int, int, int[]
Returns:
double
Method signature:
double netAmt(int evapNormal, int evapFlood, int[] rain)
(be sure your method is public)

Notes

  • A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.

Constraints

  • evapNormal will be between 0 and 1000 inclusive
  • evapFlood will be between evapNormal and 1000 inclusive
  • rain will contain between 1 and 50 elements inclusive
  • each element of rain will be between 0 and 1000 inclusive

Examples

  1. 20

    40

    {0,60,0,0}

    Returns: -35.0

    After the first day, 20 units have evaporated so we are 20 units below flood stage. After the first half of the second day, 30 units of rain have fallen while 10 units have evaporated, so we have reached flood stage. By the end of the day another 30 have fallen and 20 (40 / 2) have evaporated leaving us 10 units above flood stage. On the third day, we leave flood stage after 1/4 of a day. By the end of the day we are 15 units below flood stage. On the fourth day 20 units evaporate leaving us 35 units below flood stage.

  2. 20

    39

    {0,60}

    Returns: 10.5

    After the first day, we are 20 units below flood stage. We reach flood stage after half of the next day. During the last half of the day 30 units of rain fall while 19.5 units evaporate.

  3. 20

    40

    {0}

    Returns: -20.0

  4. 20

    40

    {1}

    Returns: -19.0

  5. 287

    912

    {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0}

    Returns: -14125.0

  6. 20

    40

    {30,40,20,0}

    Returns: -20.0

  7. 200

    800

    {0,600}

    Returns: 0.0

    After the first day, the level is 200 below flood stage due to evaporation. Halfway through the second day, 300 units have rain have fallen and 100 units have evaporated so we have just reached flood stage. After that we are at a stable equilibrium in which the level does not change.

  8. 100

    212

    {0,230,0,0,0,0,0,0}

    Returns: -598.0406386066763

  9. 100

    212

    {0,200,200,200,200,213}

    Returns: 1.0

  10. 150

    150

    {150,150,150,150,140,162,0}

    Returns: -148.0

  11. 100

    900

    {0,800,3,1000}

    Returns: 89.22222222222223

  12. 300

    379

    {0,800,0,800,512,555,1000}

    Returns: 1210.6370448548812

  13. 200

    300

    {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

    Returns: -2880.0

  14. 300

    400

    {322,389,400,400}

    Returns: 0.0

  15. 0

    3

    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    Returns: 0.0

  16. 0

    37

    {0,0,0,50,0,0,0,0}

    Returns: 0.0

  17. 200

    800

    { 0, 600 }

    Returns: 0.0

  18. 17

    35

    { 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 861 }

    Returns: 577.0584174737277

  19. 1

    2

    { 3 }

    Returns: 1.0

  20. 20

    40

    { 30, 0, 60, 0, 0, 13, 43, 21, 19 }

    Returns: -19.0

  21. 0

    10

    { 5 }

    Returns: 0.0

  22. 0

    200

    { 1 }

    Returns: 0.0

  23. 100

    200

    { 1, 2, 3, 4 }

    Returns: -390.0

  24. 123

    689

    { 0, 600, 600, 0, 0, 0, 0, 687, 364, 357, 0, 0, 0, 0, 453, 876, 754, 243, 159, 955, 466, 955, 955, 957, 0, 0, 0, 0, 0, 0, 0, 345, 786, 921, 783 }

    Returns: 351.5289980232352

  25. 10

    100

    { 10, 100, 100, 100, 1000, 10, 1, 0, 1, 1, 21, 100, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 10, 100, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 }

    Returns: 32644.0

  26. 10

    100

    { 10, 100, 100, 10, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1, 1000, 1000, 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 }

    Returns: 32409.0

  27. 20

    40

    { 0 }

    Returns: -20.0


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: