Problem Statement
Little Lucy loves to download music from the Internet. Recently she discovered a very frustrating bug in her downloading software. When Lucy downloads some files the total bandwidth is distributed evenly between all files. Currently, the download agent estimates the remaining time for each download as remaining_size / current_speed. This approach is bad since it does not take into account the possibility of some downloads finishing earlier than others, thus freeing up additional bandwidth for remaining downloads.
You are given the total bandwidth (in bytes per second) and a int[] fileSizes, the i-th element of which is the size of the i-th file (in bytes). Return a double[] containing the actual times when the downloads will finish (in seconds). The i-th element of the return value should correspond to the i-th file.
Definition
- Class:
- TimeRemain
- Method:
- estimateRemainingTime
- Parameters:
- int[], int
- Returns:
- double[]
- Method signature:
- double[] estimateRemainingTime(int[] fileSizes, int bandwidth)
- (be sure your method is public)
Notes
- Each element of the return value must be accurate to within an absolute or relative value of 1e-9.
Constraints
- fileSizes will contain between 1 and 50 elements, inclusive.
- bandwidth and each element of fileSizes will be between 1 and 1000000000, inclusive.
Examples
{10, 20, 30, 40}1
Returns: {40.0, 70.0, 90.0, 100.0 }{10, 10, 10, 10}1
Returns: {40.0, 40.0, 40.0, 40.0 }All files will be downloaded at a speed of 0.25 bytes/second, so each one will finish in 40 seconds.{8719, 98123, 120389, 120, 102938}17
Returns: {2058.5882352941176, 17835.764705882353, 19428.764705882353, 35.294117647058826, 18402.235294117647 }{10, 10, 30, 30, 50}5
Returns: {10.0, 10.0, 22.0, 22.0, 26.0 }{1000000000}1
Returns: {1.0E9 }