Statistics

Problem Statement for "QuizShow"

Problem Statement

You are a contestant on a TV quiz show. Throughout the game, you and your 2 opponents have accumulated points by answering trivia questions. At the end of the game, the three of you are given one final question. Before you hear the question, each contestant must decide how many points he or she wishes to wager. Each contestant who answers the question correctly will gain a number of points equal to his or her wager, while the others will lose a number of points equal to their respective wagers. The contestant who ends up with the highest score after the final question wins the game.

It has come to the point in the game where you must select your wager. You can bet any amount between zero and your current score, inclusive. Given your current score, the scores of your two opponents, and how much you believe each of your opponents will wager, compute how much you should wager in order to have the highest probability of winning the game. Assume that you and your opponents each independently have a 50% chance of answering the final question correctly.

You will be given the three scores as a int[], scores. The first element is your score, the next element is your first opponent's score, and the last element is your second opponent's score. You will also be given wager1 and wager2, the amount of your first and second opponents' wagers, respectively.

Your goal is to maximize your chance of winning uncontested. As far as you're concerned, ending in a tie is as bad as losing. If there are multiple wagers that give you the same highest probability of winning, return the smallest such wager. If you have no chance of winning, return zero.

Definition

Class:
QuizShow
Method:
wager
Parameters:
int[], int, int
Returns:
int
Method signature:
int wager(int[] scores, int wager1, int wager2)
(be sure your method is public)

Constraints

  • scores will contain exactly 3 elements.
  • Each element of scores will be between 0 and 10000, inclusive.
  • wager1 will be between 0 and scores[1], inclusive.
  • wager2 will be between 0 and scores[2], inclusive.

Examples

  1. { 100, 100, 100 }

    25

    75

    Returns: 76

    If you bet 76, you have a 50% chance of winning. In this case, it doesn't matter if your opponents are right or wrong. If you are right, you win. Otherwise, you lose. If you wager less than 76, your chance of winning drops below 50%, and if you wager more, your chance of winning will not increase. Therefore, the correct answer is 76.

  2. { 10, 50, 60 }

    30

    41

    Returns: 0

    Even if your opponents are both wrong, they will end up with 20 and 19 points. Since you cannot win (even if you wager 10), the correct answer is 0.

  3. { 10, 50, 60 }

    31

    41

    Returns: 10

    This is the same as the previous example, except in this case your opponents will each end up with 19 points if they are both wrong. Now, you have a 12.5% chance of winning if you wager 10.

  4. { 2, 2, 12 }

    0

    9

    Returns: 2

  5. { 2, 2, 12 }

    0

    10

    Returns: 1

  6. { 2, 2, 12 }

    0

    11

    Returns: 1

  7. { 2, 2, 12 }

    0

    12

    Returns: 1

  8. { 8243, 4248, 7923 }

    4248

    3942

    Returns: 3623

  9. { 10000, 10000, 10000 }

    9998

    9997

    Returns: 9999

  10. { 5824, 4952, 6230 }

    364

    287

    Returns: 694

  11. { 2983, 2348, 3849 }

    492

    952

    Returns: 0

  12. {429, 23, 238 }

    23

    214

    Returns: 24

  13. { 500, 1000, 1000 }

    5

    10

    Returns: 496

  14. {1000, 1000, 1000 }

    1000

    1000

    Returns: 0

  15. {1, 10000, 10000 }

    9999

    9999

    Returns: 1

  16. {10000, 2, 9998 }

    0

    9998

    Returns: 9997

  17. {10000, 3, 9998 }

    0

    9998

    Returns: 0

  18. {0,0,0}

    0

    0

    Returns: 0

  19. {1,0,0}

    0

    0

    Returns: 0

  20. {0,1,1}

    1

    1

    Returns: 0

  21. {0,1,1}

    0

    0

    Returns: 0

  22. {1,1,1}

    0

    0

    Returns: 1

  23. {7904,1734,8495}

    267

    7710

    Returns: 0

  24. {8122,2393,6614}

    2106

    3586

    Returns: 2079

  25. {1485,35,6757}

    22

    3052

    Returns: 0

  26. {7292,7914,4968}

    6764

    2358

    Returns: 35

  27. {4603,2136,5438}

    1020

    5146

    Returns: 0

  28. {785,5615,7865}

    1283

    3999

    Returns: 0

  29. {3699,9403,3084}

    7144

    1396

    Returns: 782

  30. {7808,944,3818}

    270

    581

    Returns: 0

  31. {7442,45,1991}

    6

    1348

    Returns: 0

  32. {2534,3273,5848}

    2916

    4935

    Returns: 0

  33. {2207,2284,4150}

    2268

    3378

    Returns: 0

  34. {1793,6040,7100}

    175

    5610

    Returns: 0

  35. {7634,6189,2922}

    2773

    1256

    Returns: 1329

  36. {7607,5750,767}

    4045

    383

    Returns: 2189

  37. {3169,226,782}

    196

    575

    Returns: 0

  38. {5964,3745,9524}

    1006

    2101

    Returns: 5662

  39. {6075,431,6331}

    418

    2503

    Returns: 0

  40. {1689,6174,4623}

    38

    3184

    Returns: 0

  41. {6000,3386,7074}

    670

    4016

    Returns: 0

  42. {5727,7418,7365}

    678

    6688

    Returns: 2370

  43. {8555,7234,9747}

    1213

    7872

    Returns: 0

  44. {3745,9091,7426}

    6674

    6073

    Returns: 0

  45. {1892,6505,2211}

    6088

    325

    Returns: 0

  46. {9823,1537,9521}

    911

    1025

    Returns: 724

  47. {7391,9445,3162}

    2520

    2915

    Returns: 0

  48. {1330,3900,9728}

    877

    5003

    Returns: 0

  49. {3751,3051,6680}

    2306

    609

    Returns: 3539

  50. {3603,3028,766}

    1726

    361

    Returns: 1152

  51. {9100,1779,3337}

    1468

    2792

    Returns: 0

  52. {6197,4296,8347}

    1554

    695

    Returns: 2846

  53. {3698,2693,8175}

    2270

    3224

    Returns: 1266

  54. {6520,1786,3556}

    354

    1183

    Returns: 0

  55. {9422,9142,9571}

    3332

    6069

    Returns: 6219

  56. {851,2090,6421}

    1139

    5420

    Returns: 151

  57. {8373,1439,4336}

    1176

    3560

    Returns: 0

  58. {3817,5763,9005}

    5362

    4673

    Returns: 516

  59. {9332,6790,743}

    5355

    160

    Returns: 2814

  60. {8770,6431,144}

    2557

    28

    Returns: 219

  61. {9461,7496,609}

    3029

    245

    Returns: 1065

  62. {1030,3812,3304}

    1922

    740

    Returns: 0

  63. {3229,425,8323}

    262

    7591

    Returns: 0

  64. {4372,3233,6893}

    3089

    4121

    Returns: 0

  65. {5680,5172,8584}

    937

    880

    Returns: 3785

  66. {1081,8183,4151}

    3120

    3740

    Returns: 0

  67. {5085,2567,4171}

    815

    2501

    Returns: 1588

  68. {3558,6631,6412}

    5746

    6184

    Returns: 0

  69. {6554,6330,8481}

    6255

    6423

    Returns: 0

  70. {6045,4734,7491}

    145

    5286

    Returns: 0

  71. {9572,8253,9487}

    7335

    3553

    Returns: 6017

  72. {6840,4983,2677}

    4233

    1996

    Returns: 2377

  73. { 1, 0, 0 }

    0

    0

    Returns: 0

  74. { 1000, 5, 5 }

    2

    2

    Returns: 0

  75. { 1, 1, 2 }

    1

    1

    Returns: 1

  76. { 100, 10, 10 }

    0

    0

    Returns: 0

  77. { 10, 1, 1 }

    1

    1

    Returns: 0

  78. { 1000, 100, 100 }

    25

    75

    Returns: 0

  79. { 10000, 0, 0 }

    0

    0

    Returns: 0

  80. { 5, 5, 0 }

    4

    0

    Returns: 0

  81. { 100, 50, 50 }

    0

    0

    Returns: 0

  82. { 888, 888, 444 }

    98

    97

    Returns: 0

  83. { 10, 10, 20 }

    5

    6

    Returns: 6

  84. { 9, 10, 2 }

    3

    1

    Returns: 0

  85. { 1, 0, 0 }

    0

    0

    Returns: 0

  86. { 1000, 5, 5 }

    2

    2

    Returns: 0

  87. { 1, 1, 2 }

    1

    1

    Returns: 1

  88. { 100, 10, 10 }

    0

    0

    Returns: 0

  89. { 10, 1, 1 }

    1

    1

    Returns: 0

  90. { 1000, 100, 100 }

    25

    75

    Returns: 0

  91. { 10000, 0, 0 }

    0

    0

    Returns: 0

  92. { 5, 5, 0 }

    4

    0

    Returns: 0

  93. { 100, 50, 50 }

    0

    0

    Returns: 0

  94. { 888, 888, 444 }

    98

    97

    Returns: 0

  95. { 10, 10, 20 }

    5

    6

    Returns: 6

  96. { 9, 10, 2 }

    3

    1

    Returns: 0

  97. { 1, 0, 0 }

    0

    0

    Returns: 0

  98. { 1000, 5, 5 }

    2

    2

    Returns: 0

  99. { 1, 1, 2 }

    1

    1

    Returns: 1

  100. { 100, 10, 10 }

    0

    0

    Returns: 0

  101. { 10, 1, 1 }

    1

    1

    Returns: 0

  102. { 1000, 100, 100 }

    25

    75

    Returns: 0

  103. { 10000, 0, 0 }

    0

    0

    Returns: 0

  104. { 5, 5, 0 }

    4

    0

    Returns: 0

  105. { 100, 50, 50 }

    0

    0

    Returns: 0

  106. { 888, 888, 444 }

    98

    97

    Returns: 0

  107. { 10, 10, 20 }

    5

    6

    Returns: 6

  108. { 9, 10, 2 }

    3

    1

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