Statistics

Problem Statement for "ColorfulBoxesAndBalls"

Problem Statement

You are playing a game where you have numRed red boxes, numBlue blue boxes, numRed red balls, and numBlue blue balls.
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.
Your total score is the sum of the scores of all the boxes.
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

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

  3. 5

    5

    464

    464

    464

    Returns: 4640

    No matter how you place the balls, your score will always be the same.

  4. 1

    4

    20

    -30

    -10

    Returns: -100

    The maximum total score may be less than zero.

  5. 9

    1

    -1

    -10

    4

    Returns: 0

  6. 1

    1

    0

    0

    0

    Returns: 0

  7. 100

    100

    1000

    1000

    1000

    Returns: 200000

  8. 100

    100

    -1000

    -1000

    -1000

    Returns: -200000

  9. 46

    18

    -99

    253

    76

    Returns: 0

  10. 46

    18

    -99

    252

    77

    Returns: 0

  11. 46

    18

    -99

    253

    77

    Returns: 0

  12. 4

    61

    379

    565

    277

    Returns: 35981

  13. 29

    86

    -664

    465

    -199

    Returns: 20734

  14. 98

    26

    944

    565

    126

    Returns: 107202

  15. 96

    96

    -221

    310

    782

    Returns: 150144

  16. 41

    79

    733

    110

    843

    Returns: 73306

  17. 87

    16

    969

    -997

    549

    Returns: 86367

  18. 33

    33

    -976

    -185

    -313

    Returns: -20658

  19. 29

    12

    947

    731

    -886

    Returns: 36235

  20. 46

    28

    166

    238

    655

    Returns: 39668

  21. 40

    2

    -792

    -48

    -488

    Returns: -31776

  22. 21

    50

    -611

    456

    -155

    Returns: 9969

  23. 41

    41

    -767

    792

    -947

    Returns: 1025

  24. 18

    32

    -408

    -533

    -956

    Returns: -24400

  25. 12

    48

    -767

    -747

    -27

    Returns: -27540

  26. 34

    34

    -120

    -857

    918

    Returns: 62424

  27. 36

    37

    -795

    183

    -612

    Returns: -21849

  28. 92

    92

    978

    563

    624

    Returns: 141772

  29. 97

    97

    530

    244

    -168

    Returns: 75078

  30. 77

    77

    12

    -239

    956

    Returns: 147224

  31. 82

    99

    -494

    33

    -544

    Returns: -37241

  32. 100

    4

    20

    -300

    -1

    Returns: 1912

  33. 45

    23

    -74

    67

    24

    Returns: -524

  34. 2

    2

    500

    200

    100

    Returns: 1400

  35. 8

    2

    2

    4

    8

    Returns: 44

  36. 100

    100

    999

    998

    -999

    Returns: 199700

  37. 100

    100

    -1000

    -1000

    500

    Returns: 100000

  38. 10

    10

    1

    1

    100

    Returns: 2000

  39. 63

    65

    -700

    -258

    -952

    Returns: -60870

  40. 99

    56

    3

    2

    45

    Returns: 5169

  41. 7

    4

    -5

    -2

    0

    Returns: -15

  42. 3

    2

    2

    3

    3

    Returns: 14

  43. 100

    100

    100

    200

    300

    Returns: 60000

  44. 2

    2

    -5

    -5

    -5

    Returns: -20

  45. 7

    8

    1000

    1000

    1

    Returns: 15000

  46. 10

    10

    300

    300

    1

    Returns: 6000

  47. 10

    10

    -10

    1

    0

    Returns: 0

  48. 54

    69

    522

    -630

    -17

    Returns: -11286

  49. 5

    3

    100

    200

    -500

    Returns: 1100

  50. 10

    1

    10

    501

    500

    Returns: 1090

  51. 2

    1

    1000

    900

    100

    Returns: 2900

  52. 2

    2

    100

    300

    250

    Returns: 1000

  53. 100

    100

    2

    1

    1

    Returns: 300

  54. 10

    9

    1

    10

    9

    Returns: 163

  55. 10

    4

    400

    500

    450

    Returns: 6000

  56. 1

    1

    2

    -6

    2

    Returns: 4

  57. 1

    1

    1

    1

    10

    Returns: 20

  58. 100

    90

    20

    19

    21

    Returns: 3980

  59. 2

    3

    400

    100

    300

    Returns: 1300


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: