Statistics

Problem Statement for "RaceManagement"

Problem Statement

Your company runs a horse race betting service. Each person bets on a horse, and if that horse wins outright (i.e., it wins alone and doesn't tie for the win with any other hose), the person will win back their money plus a multiple of the amount they bet. This multiple is called a payout factor. In all other cases your company keeps the money. You are given a int[] probability and a int[] amounts. The ith element of probability is the percentage chance of the ith horse winning the race, and the ith element of amounts is the amount bet on the ith horse. These probabilities are independent (see example 1 for clarification). Return the highest payout factor such that the expected earnings of the company is minimumMoney or higher. If you can not achieve minimumMoney with a non-negative payout factor, then return -1. If you can achieve minimumMoney with any payout factor, then return -2.

Definition

Class:
RaceManagement
Method:
getPayoutFactor
Parameters:
int[], int[], int
Returns:
double
Method signature:
double getPayoutFactor(int[] probability, int[] amounts, int minimumMoney)
(be sure your method is public)

Notes

  • The returned value must have an absolute or relative error less than 1e-9.

Constraints

  • probability will contain between 1 and 5 elements, inclusive.
  • Each element of probability will be between 0 and 100, inclusive.
  • Each element of amounts will be between 0 and 1000, inclusive.
  • amounts will contain the same number of elements as probability.
  • The sum of all the elements in probability will be at most 100.
  • minimumMoney will be between 0 and 1000, inclusive.

Examples

  1. {30}

    {100}

    10

    Returns: 2.0

    Horse 1 has a 30% chance of winning. If it wins, the company has to pay out 100*P dollars, where P is the payout factor, and if it doesn't win, the company gains 100 dollars. Thus, the expected earnings of the compay is 70-30*P. The highest payout factor that ensures this is at least 10 is 2.

  2. {50,40}

    {300,200}

    100

    Returns: 2.076923076923077

    Horse A has a 50% chance of winning and horse B has a 40% chance of winning. But this also means that there is a 20% chance they tie and a remaining 30% chance neither of them wins. Thus, in this scenario, 4 cases arise Horse A wins 30% chance => The company loses 300*P dollars and gains 200 dollars Horse B wins 20% chance => The company loses 200*P dollars and gains 300 dollars Horse A & B both win (tie) 20% chance => The company loses 0*P dollars and gains 500 dollars Neither Horse A nor horse B wins (No result) 30% chance => The company loses 0*P dollars and gains 500 dollars To ensure the expected earnings are at least 100, the payout factor P can be at most approximately 2.077.

  3. {10,10,10}

    {100,100,100}

    12

    Returns: 10.851851851851851

  4. {30,20,10}

    {100,200,300}

    100

    Returns: 6.861635220125786

  5. {50}

    {100}

    1000

    Returns: -1.0

    Return -1 because the payout factor in this case will be negative.

  6. {0}

    {100}

    100

    Returns: -2.0

    The payout factor is irrelevant. The company always gains 100 dollars.

  7. {0}

    {100}

    200

    Returns: -1.0

  8. {100}

    {100}

    100

    Returns: -1.0

  9. {100}

    {0}

    100

    Returns: -1.0

  10. {100}

    {100}

    10

    Returns: -1.0

  11. {49,31,3,3}

    {637,361,549,601}

    388

    Returns: 5.5642566807308

  12. {91,9,0,0,0}

    {745,811,481,941,903}

    181

    Returns: 4.93420791796551

  13. {34,65,0}

    {621,729,86}

    188

    Returns: 2.2278088144009933

  14. {56,14,29,1,0}

    {604,548,839,764,236}

    817

    Returns: 5.764322718740284

  15. {37,30,28,4,1}

    {863,188,796,614,96}

    511

    Returns: 6.341439206765301

  16. {21,59}

    {105,660}

    287

    Returns: 0.5094744786707782

  17. {91,9}

    {241,655}

    147

    Returns: 2.655841341366748

  18. {80,12,1,7,0}

    {315,363,215,46,702}

    310

    Returns: 5.245643792496961

  19. {97,0,2,0,1}

    {641,55,827,299,840}

    349

    Returns: 2.8296004811766347

  20. {9,18,29,18,4}

    {323,5,157,256,690}

    209

    Returns: 15.088961223920425

  21. {52,38,5,2,1}

    {874,739,312,65,707}

    325

    Returns: 5.069966826773921

  22. {0,0,0,0}

    {100,100,100,100}

    350

    Returns: -2.0

  23. {20,20,20,20,20}

    {10,10,10,10,10}

    1000

    Returns: -1.0

  24. {50,50}

    {10,10}

    500

    Returns: -1.0

  25. {1,1,1,1,1}

    {500,500,500,500,500}

    750

    Returns: 71.87142489796517

  26. {0,100,0,0}

    {100,0,200,500}

    450

    Returns: -2.0

  27. {0,50,0,0,50}

    {10,0,20,70,0}

    370

    Returns: -1.0

  28. {0,0,100,0,0}

    {0,0,180,0,0}

    950

    Returns: -1.0

  29. {0,0,30,0,50}

    {0,0,70,0,80}

    100

    Returns: 0.2987012987012987

  30. {0,0,0,0,100}

    {0,0,0,0,40}

    50

    Returns: -1.0

  31. {20,20,1,20,1}

    {10,500,10,10,500}

    70

    Returns: 13.155002944240612

  32. {100}

    {20}

    100

    Returns: -1.0

  33. {100}

    {0}

    50

    Returns: -1.0

  34. {0}

    {0}

    60

    Returns: -1.0

  35. {0}

    {170}

    50

    Returns: -2.0

  36. {0}

    {890}

    420

    Returns: -2.0

  37. {50, 40 }

    {300, 200 }

    100

    Returns: 2.076923076923077

  38. {20, 18, 14, 32, 12 }

    {140, 200, 180, 120, 320 }

    294

    Returns: 8.47036366123654

  39. {15, 16, 17, 18, 19 }

    {29, 28, 27, 26, 25 }

    50

    Returns: 6.837560730100021

  40. {100 }

    {0 }

    101

    Returns: -1.0

  41. {10, 50, 5, 15, 19 }

    {60, 100, 25, 75, 105 }

    50

    Returns: 6.337901176815901

  42. {0 }

    {100 }

    120

    Returns: -1.0

  43. {0, 10, 30, 20 }

    {0, 0, 0, 0 }

    10

    Returns: -1.0

  44. {0 }

    {100 }

    101

    Returns: -1.0

  45. {25, 24, 23, 12, 10 }

    {111, 222, 333, 444, 555 }

    987

    Returns: 4.9323538208695

  46. {10, 10, 33, 44, 1 }

    {166, 266, 366, 466, 566 }

    666

    Returns: 5.44652321557496

  47. {20, 30, 40 }

    {100, 100, 100 }

    100

    Returns: 3.424778761061947

  48. {30, 20, 15, 35 }

    {100, 50, 20, 60 }

    10

    Returns: 6.79713278162712

  49. {34, 12, 22, 11 }

    {100, 333, 222, 11 }

    15

    Returns: 9.034966967256441

  50. {0 }

    {50 }

    100

    Returns: -1.0

  51. {30, 13, 35, 2, 3 }

    {0, 0, 1, 1, 999 }

    133

    Returns: 72.33154747359897

  52. {0 }

    {100 }

    100

    Returns: -2.0

  53. {0 }

    {100 }

    110

    Returns: -1.0

  54. {0 }

    {0 }

    1

    Returns: -1.0

  55. {50 }

    {100 }

    1000

    Returns: -1.0

  56. {0, 0 }

    {0, 0 }

    1

    Returns: -1.0

  57. {0, 100 }

    {20, 20 }

    10

    Returns: 0.5

  58. {10, 50, 5, 10, 10 }

    {100, 200, 300, 400, 500 }

    250

    Returns: 10.04264670156143

  59. {0, 0, 0 }

    {10, 10, 10 }

    1000

    Returns: -1.0

  60. {30, 20, 10, 20, 6 }

    {300, 800, 250, 30, 150 }

    900

    Returns: 3.451335457162043

  61. {0, 100 }

    {100, 0 }

    200

    Returns: -1.0

  62. {0 }

    {10 }

    100

    Returns: -1.0

  63. {0 }

    {100 }

    1000

    Returns: -1.0

  64. {100 }

    {0 }

    1000

    Returns: -1.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: