Statistics

Problem Statement for "SwimmingPool"

Problem Statement

A swimming pool of a very complicated shape, but of uniform depth is filled to a certain height one day by the rain. You have determined the rates at which water entered the swimming pool in cubic meters per second for a number of time periods. With this information you are able to calculate the total volume of water that entered the pool, and given the height to which the pool was filled, you can now determine the cross-sectional area of the pool. For example, if a total volume of 100 cubic meters of water flowed into the pool and filled it up to a height of 10 meters, then you would know that the cross-sectional area of the pool was 10 square meters.

You must write a method that takes as input a int[] corresponding to rates in cubic meters per minute, another int[] that corresponds to the durations for which each of the rates occurs, and an int which gives the height to which the pool is filled. Your method must compute the cross-sectional area of the pool and return the largest integer that is less than or equal to this area.

Definition

Class:
SwimmingPool
Method:
area
Parameters:
int[], int[], int
Returns:
int
Method signature:
int area(int[] rates, int[] durations, int height)
(be sure your method is public)

Constraints

  • rates will contain between 1 and 50 elements, inclusive.
  • rates and durations will contain the same number of elements.
  • Each element of rates will be between 1 and 100, inclusive.
  • Each element of durations will be between 1 and 100, inclusive.
  • height will be between 1 and 100, inclusive.

Examples

  1. {1,2,3,4}

    {1,2,3,4}

    10

    Returns: 3

  2. {1,2,3,4,5}

    {5,4,3,2,1}

    1

    Returns: 35

    the total amount of rain to fall is 35 cubic meters. Thus the cross-sectional area is 3.5.

  3. {1,2,3,4,5}

    {5,4,3,2,1}

    10

    Returns: 3

    The total amount of rain to fall is 35 cubic meters. Thus the cross-sectional area is 3.5.

  4. {5,4,3,2,1}

    {1,2,3,4,5}

    100

    Returns: 0

  5. {100}

    {1}

    100

    Returns: 1

  6. {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    100

    Returns: 5000

  7. {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    97

    Returns: 5154

  8. {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    1

    Returns: 500000

  9. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50}

    {50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}

    45

    Returns: 491

  10. {5,8,4,3}

    {4,2,3,9}

    64

    Returns: 1

  11. {3,1,4,1,5,9,2,7}

    {2,7,7,2,7,7,2,3}

    54

    Returns: 3

  12. {56,1,2,6,4,9}

    {5,65,32,48,59,2}

    5

    Returns: 190

  13. {3}

    {1}

    4

    Returns: 0

  14. {5,5,5,5,5}

    {6,7,8,9,10}

    2

    Returns: 100

  15. {1,2,3,4,5}

    {5,4,3,2,1}

    10

    Returns: 3

  16. {25,25}

    {10,15}

    7

    Returns: 89

  17. {5,8,4,3}

    {4,3,2,9}

    64

    Returns: 1

  18. { 1, 2, 3, 4 }

    { 1, 2, 3, 4 }

    10

    Returns: 3

  19. { 1, 2, 3, 4, 5 }

    { 5, 4, 3, 2, 1 }

    10

    Returns: 3

  20. { 5, 5, 5, 5, 5 }

    { 6, 7, 8, 9, 10 }

    2

    Returns: 100

  21. { 25, 25 }

    { 10, 15 }

    7

    Returns: 89

  22. { 3 }

    { 1 }

    4

    Returns: 0

  23. { 1, 2, 3, 4, 5 }

    { 5, 4, 3, 2, 1 }

    1

    Returns: 35


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: