Problem Statement
You must place a single ball into each box. Each box is then scored as follows:
- If the box is red and it contains a red ball, you get onlyRed points.
- If the box is blue and it contains a blue ball, you get onlyBlue points.
- In all other cases, you get bothColors points.
Return the maximum possible total score you can get.
Definition
- Class:
- ColorfulBoxesAndBalls
- Method:
- getMaximum
- Parameters:
- int, int, int, int, int
- Returns:
- int
- Method signature:
- int getMaximum(int numRed, int numBlue, int onlyRed, int onlyBlue, int bothColors)
- (be sure your method is public)
Constraints
- numRed and numBlue will each be between 1 and 100, inclusive.
- onlyRed, onlyBlue, and bothColors will each be between -1000 and 1000, inclusive.
Examples
2
3
100
400
200
Returns: 1400
In this example, you should put two red balls into red boxes, and three blue balls into blue boxes. Then you can get 100 * 2 + 400 * 3 = 1400 points in total.
2
3
100
400
300
Returns: 1600
bothColors is a larger value here than it was in the previous example. You should put two blue balls into red boxes, and two red balls and one blue ball into blue boxes. Then you can get 300 * 4 + 400 * 1 = 1600 points.
5
5
464
464
464
Returns: 4640
No matter how you place the balls, your score will always be the same.
1
4
20
-30
-10
Returns: -100
The maximum total score may be less than zero.
9
1
-1
-10
4
Returns: 0
1
1
0
0
0
Returns: 0
100
100
1000
1000
1000
Returns: 200000
100
100
-1000
-1000
-1000
Returns: -200000
46
18
-99
253
76
Returns: 0
46
18
-99
252
77
Returns: 0
46
18
-99
253
77
Returns: 0
4
61
379
565
277
Returns: 35981
29
86
-664
465
-199
Returns: 20734
98
26
944
565
126
Returns: 107202
96
96
-221
310
782
Returns: 150144
41
79
733
110
843
Returns: 73306
87
16
969
-997
549
Returns: 86367
33
33
-976
-185
-313
Returns: -20658
29
12
947
731
-886
Returns: 36235
46
28
166
238
655
Returns: 39668
40
2
-792
-48
-488
Returns: -31776
21
50
-611
456
-155
Returns: 9969
41
41
-767
792
-947
Returns: 1025
18
32
-408
-533
-956
Returns: -24400
12
48
-767
-747
-27
Returns: -27540
34
34
-120
-857
918
Returns: 62424
36
37
-795
183
-612
Returns: -21849
92
92
978
563
624
Returns: 141772
97
97
530
244
-168
Returns: 75078
77
77
12
-239
956
Returns: 147224
82
99
-494
33
-544
Returns: -37241
100
4
20
-300
-1
Returns: 1912
45
23
-74
67
24
Returns: -524
2
2
500
200
100
Returns: 1400
8
2
2
4
8
Returns: 44
100
100
999
998
-999
Returns: 199700
100
100
-1000
-1000
500
Returns: 100000
10
10
1
1
100
Returns: 2000
63
65
-700
-258
-952
Returns: -60870
99
56
3
2
45
Returns: 5169
7
4
-5
-2
0
Returns: -15
3
2
2
3
3
Returns: 14
100
100
100
200
300
Returns: 60000
2
2
-5
-5
-5
Returns: -20
7
8
1000
1000
1
Returns: 15000
10
10
300
300
1
Returns: 6000
10
10
-10
1
0
Returns: 0
54
69
522
-630
-17
Returns: -11286
5
3
100
200
-500
Returns: 1100
10
1
10
501
500
Returns: 1090
2
1
1000
900
100
Returns: 2900
2
2
100
300
250
Returns: 1000
100
100
2
1
1
Returns: 300
10
9
1
10
9
Returns: 163
10
4
400
500
450
Returns: 6000
1
1
2
-6
2
Returns: 4
1
1
1
1
10
Returns: 20
100
90
20
19
21
Returns: 3980
2
3
400
100
300
Returns: 1300