Statistics

Problem Statement for "BusyTime"

Problem Statement

We have a collection of jobs to run on k processors. Each job requires a certain amount of processor time, but is migratable and preemptible -- it can be started on one processor, suspended, continued on another processor, etc., as long as the total time it gets on processors is sufficient.

How long can we keep all k processors busy? Given k and int[] need (the processor time needed by each job), return the maximum possible time we can keep all k processors busy with optimal scheduling.

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

  1. 3

    {100,75}

    Returns: 0.0

    With only 2 jobs we can never have all 3 processors busy.

  2. 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. 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.

  4. 3

    {1000,100,1,2000,79,125}

    Returns: 305.0

  5. 1

    {982}

    Returns: 982.0

  6. 7

    { 35, 47, 82, 10, 11, 23, 99, 50, 19, 24, 67, 70, 80 }

    Returns: 86.33333333333333

  7. 2

    {2, 2, 2, 2}

    Returns: 4.0

  8. 2

    {1, 2, 4, 5}

    Returns: 6.0

  9. 3

    {1, 2, 2, 2, 2, 7, 4, 4}

    Returns: 8.0

  10. 3

    {2, 2, 2, 3, 3, 3, 4, 2}

    Returns: 7.0

  11. 2

    {3, 3, 1}

    Returns: 3.5

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 3

    {100,1,100,98}

    Returns: 99.0

  18. 2

    {100,1,100,98}

    Returns: 149.5


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: