Problem Statement
How long can we keep all k processors busy? Given k and
Definition
- Class:
- BusyTime
- Method:
- busy
- Parameters:
- int, int[]
- Returns:
- double
- Method signature:
- double busy(int k, int[] need)
- (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
- k will be between 1 and 50, inclusive.
- need will contain between 1 and 50 elements, inclusive.
- Each element of need will be between 1 and 1,000,000, inclusive.
Examples
3
{100,75}
Returns: 0.0
With only 2 jobs we can never have all 3 processors busy.
2
{2000,100,100}
Returns: 200.0
We can run job A on processor 1 and job B on processor 2. When job B finishes after 100 time units, we can put job C on processor 2 for the next 100 time units. But now we only have 1 job that needs to run, so we can't keep both processors busy any longer.
3
{20,20,21,100}
Returns: 30.5
We can run job A on processor 1 from time 0 to time 20. We can run job B on processor 2 from time 10.5 to time 30.5. We can run job C on processor 2 from time 0 to time 10.5 and then on processor 1 from time 20 to time 30.5. We can run job D on processor 3 from time 0 to time 100.
3
{1000,100,1,2000,79,125}
Returns: 305.0
1
{982}
Returns: 982.0
7
{ 35, 47, 82, 10, 11, 23, 99, 50, 19, 24, 67, 70, 80 }
Returns: 86.33333333333333
2
{2, 2, 2, 2}
Returns: 4.0
2
{1, 2, 4, 5}
Returns: 6.0
3
{1, 2, 2, 2, 2, 7, 4, 4}
Returns: 8.0
3
{2, 2, 2, 3, 3, 3, 4, 2}
Returns: 7.0
2
{3, 3, 1}
Returns: 3.5
1
{9404, 31975, 35881, 69673, 100159, 117090, 140360, 141482, 144214, 161316, 195954, 203886, 211820, 219702, 225354, 228952, 252578, 307283, 315534, 398426, 435838, 448188, 470289, 517184, 541140, 544563, 570860, 600437, 621160, 631972, 696680, 712892, 747898, 785968, 802564, 846912, 853842, 885163, 956438, 957852, 958756, 962338, 993284, 996182}
Returns: 2.1049443E7
2
{50886, 75576, 86335, 124353, 129247, 141714, 235632, 259114, 283109, 304786, 326643, 332949, 360666, 387694, 398023, 525908, 530635, 534229, 563196, 612870, 630678, 638497, 640074, 663794, 667617, 679758, 715819, 729148, 734234, 746872, 749605, 812978, 817503, 827830, 829147, 874675, 895720, 918611, 979936}
Returns: 1.04080305E7
1
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000}
Returns: 5.0E7
50
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000}
Returns: 1000000.0
49
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000}
Returns: 1020408.1632653062
3
{100,1,100,98}
Returns: 99.0
2
{100,1,100,98}
Returns: 149.5