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
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
{ 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.
{ 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.
{ 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.
{ 2, 2, 12 }
0
9
Returns: 2
{ 2, 2, 12 }
0
10
Returns: 1
{ 2, 2, 12 }
0
11
Returns: 1
{ 2, 2, 12 }
0
12
Returns: 1
{ 8243, 4248, 7923 }
4248
3942
Returns: 3623
{ 10000, 10000, 10000 }
9998
9997
Returns: 9999
{ 5824, 4952, 6230 }
364
287
Returns: 694
{ 2983, 2348, 3849 }
492
952
Returns: 0
{429, 23, 238 }
23
214
Returns: 24
{ 500, 1000, 1000 }
5
10
Returns: 496
{1000, 1000, 1000 }
1000
1000
Returns: 0
{1, 10000, 10000 }
9999
9999
Returns: 1
{10000, 2, 9998 }
0
9998
Returns: 9997
{10000, 3, 9998 }
0
9998
Returns: 0
{0,0,0}
0
0
Returns: 0
{1,0,0}
0
0
Returns: 0
{0,1,1}
1
1
Returns: 0
{0,1,1}
0
0
Returns: 0
{1,1,1}
0
0
Returns: 1
{7904,1734,8495}
267
7710
Returns: 0
{8122,2393,6614}
2106
3586
Returns: 2079
{1485,35,6757}
22
3052
Returns: 0
{7292,7914,4968}
6764
2358
Returns: 35
{4603,2136,5438}
1020
5146
Returns: 0
{785,5615,7865}
1283
3999
Returns: 0
{3699,9403,3084}
7144
1396
Returns: 782
{7808,944,3818}
270
581
Returns: 0
{7442,45,1991}
6
1348
Returns: 0
{2534,3273,5848}
2916
4935
Returns: 0
{2207,2284,4150}
2268
3378
Returns: 0
{1793,6040,7100}
175
5610
Returns: 0
{7634,6189,2922}
2773
1256
Returns: 1329
{7607,5750,767}
4045
383
Returns: 2189
{3169,226,782}
196
575
Returns: 0
{5964,3745,9524}
1006
2101
Returns: 5662
{6075,431,6331}
418
2503
Returns: 0
{1689,6174,4623}
38
3184
Returns: 0
{6000,3386,7074}
670
4016
Returns: 0
{5727,7418,7365}
678
6688
Returns: 2370
{8555,7234,9747}
1213
7872
Returns: 0
{3745,9091,7426}
6674
6073
Returns: 0
{1892,6505,2211}
6088
325
Returns: 0
{9823,1537,9521}
911
1025
Returns: 724
{7391,9445,3162}
2520
2915
Returns: 0
{1330,3900,9728}
877
5003
Returns: 0
{3751,3051,6680}
2306
609
Returns: 3539
{3603,3028,766}
1726
361
Returns: 1152
{9100,1779,3337}
1468
2792
Returns: 0
{6197,4296,8347}
1554
695
Returns: 2846
{3698,2693,8175}
2270
3224
Returns: 1266
{6520,1786,3556}
354
1183
Returns: 0
{9422,9142,9571}
3332
6069
Returns: 6219
{851,2090,6421}
1139
5420
Returns: 151
{8373,1439,4336}
1176
3560
Returns: 0
{3817,5763,9005}
5362
4673
Returns: 516
{9332,6790,743}
5355
160
Returns: 2814
{8770,6431,144}
2557
28
Returns: 219
{9461,7496,609}
3029
245
Returns: 1065
{1030,3812,3304}
1922
740
Returns: 0
{3229,425,8323}
262
7591
Returns: 0
{4372,3233,6893}
3089
4121
Returns: 0
{5680,5172,8584}
937
880
Returns: 3785
{1081,8183,4151}
3120
3740
Returns: 0
{5085,2567,4171}
815
2501
Returns: 1588
{3558,6631,6412}
5746
6184
Returns: 0
{6554,6330,8481}
6255
6423
Returns: 0
{6045,4734,7491}
145
5286
Returns: 0
{9572,8253,9487}
7335
3553
Returns: 6017
{6840,4983,2677}
4233
1996
Returns: 2377
{ 1, 0, 0 }
0
0
Returns: 0
{ 1000, 5, 5 }
2
2
Returns: 0
{ 1, 1, 2 }
1
1
Returns: 1
{ 100, 10, 10 }
0
0
Returns: 0
{ 10, 1, 1 }
1
1
Returns: 0
{ 1000, 100, 100 }
25
75
Returns: 0
{ 10000, 0, 0 }
0
0
Returns: 0
{ 5, 5, 0 }
4
0
Returns: 0
{ 100, 50, 50 }
0
0
Returns: 0
{ 888, 888, 444 }
98
97
Returns: 0
{ 10, 10, 20 }
5
6
Returns: 6
{ 9, 10, 2 }
3
1
Returns: 0
{ 1, 0, 0 }
0
0
Returns: 0
{ 1000, 5, 5 }
2
2
Returns: 0
{ 1, 1, 2 }
1
1
Returns: 1
{ 100, 10, 10 }
0
0
Returns: 0
{ 10, 1, 1 }
1
1
Returns: 0
{ 1000, 100, 100 }
25
75
Returns: 0
{ 10000, 0, 0 }
0
0
Returns: 0
{ 5, 5, 0 }
4
0
Returns: 0
{ 100, 50, 50 }
0
0
Returns: 0
{ 888, 888, 444 }
98
97
Returns: 0
{ 10, 10, 20 }
5
6
Returns: 6
{ 9, 10, 2 }
3
1
Returns: 0
{ 1, 0, 0 }
0
0
Returns: 0
{ 1000, 5, 5 }
2
2
Returns: 0
{ 1, 1, 2 }
1
1
Returns: 1
{ 100, 10, 10 }
0
0
Returns: 0
{ 10, 1, 1 }
1
1
Returns: 0
{ 1000, 100, 100 }
25
75
Returns: 0
{ 10000, 0, 0 }
0
0
Returns: 0
{ 5, 5, 0 }
4
0
Returns: 0
{ 100, 50, 50 }
0
0
Returns: 0
{ 888, 888, 444 }
98
97
Returns: 0
{ 10, 10, 20 }
5
6
Returns: 6
{ 9, 10, 2 }
3
1
Returns: 0