Statistics

Problem Statement for "EllysBlood"

Problem Statement

Elly had a strange dream in which she was a nurse. After telling Kris and Stancho about it, Stancho admitted he also often has dreams in which Elly is a nurse, but his dreams are… somewhat different.


In Elly's dream she was in charge of distributing the blood banks in a hospital. There are four main types of blood: O, A, B, and AB. The O-type is most useful – it can be given to patients of any blood type. The A-type can be given to patients with blood type A or AB. The B-type can be given to patients with blood type B or AB. The AB-type can be given only to patients with blood type AB.


In the hospital there are have[0] banks of type O, have[1] banks of type A, have[2] banks of type B and have[3] banks of type AB. There are also need[0] patients with blood type O, need[1] patients with blood type A, need[2] patients with blood type B and need[3] patients with blood type AB. For the sake of this task we'll consider that each patient needs exactly one bank of blood.


Determine what is the maximal number of patients who can receive a bank of blood if they are distributed optimally.

Definition

Class:
EllysBlood
Method:
getMax
Parameters:
int[], int[]
Returns:
int
Method signature:
int getMax(int[] have, int[] need)
(be sure your method is public)

Constraints

  • have will contain exactly 4 elements.
  • Each element in have will be between 0 and 100, inclusive.
  • need will contain exactly 4 elements.
  • Each element in need will be between 0 and 100, inclusive.

Examples

  1. {9, 17, 12, 5}

    {5, 11, 26, 10}

    Returns: 42

    Elly can give blood of type A to the 11 patients with blood type A, and the remaining 6 banks to patients with blood type AB. This way the remaining 4 patients with blood type AB can get banks of type AB. The last one bank of type AB cannot be used by anyone. From the 26 patients with blood type B only 21 can get a blood bank (12 banks of type B and 9 banks of type O). With this distribution none of the patients needing blood type O gets a bank. The final count is 0 + 11 + 21 + 10 = 42. Although there are other ways to distribute the blood banks, none of them yields a number greater than 42.

  2. {100, 0, 0, 0}

    {1, 3, 3, 7}

    Returns: 14

    Remember that blood type O is the universal donor - it can be given to anyone.

  3. {0, 0, 0, 0}

    {100, 100, 100, 100}

    Returns: 0

    With no blood banks available there is nothing the girl can do.

  4. {10, 20, 30, 40}

    {40, 30, 20, 10}

    Returns: 60

    Here O can donate to O, A can donate to A, B can donate to B and AB can donate to AB. The result is 10 + 20 + 20 + 10 = 60.

  5. {0, 0, 0, 0}

    {0, 0, 0, 0}

    Returns: 0

  6. {100, 100, 100, 100}

    {0, 0, 0, 0}

    Returns: 0

  7. {0, 0, 0, 0}

    {100, 100, 100, 100}

    Returns: 0

  8. {100, 100, 100, 100}

    {100, 100, 100, 100}

    Returns: 400

  9. {40, 30, 20, 10}

    {10, 20, 30, 40}

    Returns: 100

  10. {1, 3, 3, 7}

    {4, 2, 4, 2}

    Returns: 8

  11. {4, 2, 4, 2}

    {1, 3, 3, 7}

    Returns: 12

  12. {13, 50, 4, 5}

    {13, 42, 0, 17}

    Returns: 72

  13. {17, 11, 11, 3}

    {13, 10, 10, 10}

    Returns: 42

  14. {13, 42, 17, 69}

    {5, 39, 19, 77}

    Returns: 140

  15. {66, 47, 58, 56}

    {38, 36, 75, 55}

    Returns: 204

  16. {38, 58, 83, 4}

    {47, 30, 0, 38}

    Returns: 106

  17. {5, 6, 57, 42}

    {25, 66, 83, 22}

    Returns: 90

  18. {85, 79, 0, 36}

    {16, 73, 42, 53}

    Returns: 184

  19. {24, 60, 80, 0}

    {48, 40, 2, 74}

    Returns: 140

  20. {23, 42, 15, 26}

    {77, 63, 81, 89}

    Returns: 106

  21. {57, 62, 7, 0}

    {78, 91, 57, 71}

    Returns: 126

  22. {100, 27, 100, 37}

    {44, 59, 1, 34}

    Returns: 138

  23. {7, 16, 26, 73}

    {89, 77, 60, 39}

    Returns: 88

  24. {3, 37, 25, 68}

    {58, 98, 98, 82}

    Returns: 133

  25. {30, 58, 9, 100}

    {8, 36, 21, 2}

    Returns: 67

  26. {30, 79, 22, 45}

    {85, 48, 22, 33}

    Returns: 133

  27. {30, 94, 11, 38}

    {49, 61, 31, 85}

    Returns: 173

  28. {78, 56, 48, 75}

    {6, 84, 85, 100}

    Returns: 257

  29. {56, 30, 25, 19}

    {99, 51, 31, 8}

    Returns: 119

  30. {57, 47, 34, 6}

    {60, 93, 55, 21}

    Returns: 144

  31. {14, 59, 30, 26}

    {60, 1, 62, 61}

    Returns: 106

  32. {97, 90, 85, 2}

    {53, 19, 61, 91}

    Returns: 224

  33. {4, 71, 59, 49}

    {10, 46, 29, 59}

    Returns: 138

  34. {16, 94, 35, 22}

    {2, 72, 26, 6}

    Returns: 106

  35. {44, 68, 57, 44}

    {82, 93, 1, 14}

    Returns: 127

  36. {96, 17, 48, 22}

    {57, 35, 0, 11}

    Returns: 103

  37. {72, 7, 74, 53}

    {61, 78, 79, 56}

    Returns: 206

  38. {61, 10, 67, 39}

    {37, 27, 35, 87}

    Returns: 177

  39. {80, 98, 35, 0}

    {91, 31, 65, 4}

    Returns: 150

  40. {51, 68, 51, 73}

    {18, 44, 63, 21}

    Returns: 146

  41. {29, 80, 14, 78}

    {65, 46, 65, 1}

    Returns: 90

  42. {3, 22, 6, 89}

    {0, 17, 81, 90}

    Returns: 116

  43. {61, 5, 6, 80}

    {36, 66, 21, 68}

    Returns: 140

  44. {20, 19, 99, 77}

    {57, 85, 14, 48}

    Returns: 101

  45. {87, 4, 13, 36}

    {18, 46, 96, 14}

    Returns: 118

  46. {3, 3, 40, 90}

    {60, 22, 99, 72}

    Returns: 118

  47. {36, 76, 57, 2}

    {39, 98, 54, 13}

    Returns: 171

  48. {14, 58, 17, 60}

    {36, 56, 31, 29}

    Returns: 116

  49. {23, 72, 74, 86}

    {76, 90, 15, 53}

    Returns: 163

  50. {41, 86, 34, 4}

    {22, 56, 35, 39}

    Returns: 152

  51. {79, 80, 53, 41}

    {13, 37, 44, 28}

    Returns: 122

  52. {100, 24, 50, 1}

    {69, 67, 63, 70}

    Returns: 175

  53. {11, 98, 25, 11}

    {50, 82, 97, 18}

    Returns: 136

  54. {98, 96, 46, 46}

    {53, 49, 69, 71}

    Returns: 242

  55. {76, 60, 50, 45}

    {68, 63, 61, 66}

    Returns: 231

  56. {10, 85, 93, 47}

    {79, 47, 33, 43}

    Returns: 133

  57. {11, 75, 91, 2}

    {61, 7, 78, 27}

    Returns: 123

  58. {9, 90, 67, 34}

    {18, 96, 51, 90}

    Returns: 200

  59. {18, 0, 37, 50}

    {24, 0, 80, 54}

    Returns: 105

  60. {82, 92, 86, 61}

    {76, 5, 84, 10}

    Returns: 175

  61. {58, 4, 29, 55}

    {30, 96, 98, 21}

    Returns: 112

  62. {86, 33, 24, 78}

    {25, 73, 19, 31}

    Returns: 148

  63. {16, 92, 45, 14}

    {47, 35, 72, 8}

    Returns: 104

  64. {20, 97, 71, 64}

    {31, 46, 67, 50}

    Returns: 183

  65. {55, 43, 34, 48}

    {78, 39, 75, 100}

    Returns: 180

  66. {38, 13, 31, 6}

    {38, 58, 27, 7}

    Returns: 85

  67. {78, 22, 63, 30}

    {15, 36, 73, 66}

    Returns: 190

  68. {18, 47, 75, 9}

    {77, 3, 28, 67}

    Returns: 116

  69. {73, 55, 50, 48}

    {40, 46, 9, 72}

    Returns: 167

  70. {94, 62, 42, 52}

    {8, 30, 18, 22}

    Returns: 78

  71. {0, 22, 12, 87}

    {31, 88, 13, 92}

    Returns: 121

  72. {19, 32, 38, 96}

    {65, 54, 7, 22}

    Returns: 80

  73. {48, 6, 11, 34}

    {53, 23, 58, 76}

    Returns: 99

  74. {93, 74, 30, 61}

    {30, 89, 36, 21}

    Returns: 176

  75. {25, 21, 3, 75}

    {57, 96, 76, 66}

    Returns: 115

  76. {26, 45, 76, 40}

    {57, 15, 5, 89}

    Returns: 135

  77. {11, 25, 3, 57}

    {99, 17, 96, 59}

    Returns: 90

  78. {41, 9, 100, 93}

    {87, 81, 36, 37}

    Returns: 123

  79. {6, 84, 4, 8}

    {73, 20, 28, 28}

    Returns: 58

  80. {65, 10, 18, 38}

    {64, 24, 25, 65}

    Returns: 131

  81. {56, 93, 48, 46}

    {15, 99, 54, 67}

    Returns: 235

  82. {87, 8, 47, 80}

    {80, 3, 63, 29}

    Returns: 166

  83. {6, 23, 74, 64}

    {67, 56, 85, 1}

    Returns: 104

  84. {9, 44, 94, 63}

    {22, 87, 89, 82}

    Returns: 210

  85. {57, 74, 17, 70}

    {17, 90, 15, 47}

    Returns: 169

  86. {91, 25, 63, 66}

    {6, 94, 77, 74}

    Returns: 245

  87. {84, 28, 57, 73}

    {5, 79, 86, 62}

    Returns: 231

  88. {88, 31, 68, 45}

    {86, 78, 28, 25}

    Returns: 172

  89. {17, 79, 96, 45}

    {64, 56, 70, 15}

    Returns: 158

  90. {9, 75, 12, 5}

    {73, 3, 49, 92}

    Returns: 101

  91. {30, 15, 78, 62}

    {40, 8, 72, 32}

    Returns: 142

  92. {91, 15, 94, 85}

    {2, 12, 92, 73}

    Returns: 179

  93. {59, 42, 33, 78}

    {87, 13, 66, 73}

    Returns: 178

  94. {73, 91, 21, 59}

    {50, 35, 92, 60}

    Returns: 189

  95. {65, 38, 3, 64}

    {29, 1, 24, 8}

    Returns: 62

  96. {15, 96, 46, 69}

    {17, 49, 2, 73}

    Returns: 139

  97. {89, 49, 81, 20}

    {13, 1, 73, 56}

    Returns: 143

  98. {8, 26, 11, 8}

    {1, 75, 83, 8}

    Returns: 53

  99. {28, 17, 80, 63}

    {27, 0, 9, 45}

    Returns: 81

  100. {42, 57, 60, 14}

    {11, 29, 50, 38}

    Returns: 128

  101. {26, 78, 6, 35}

    {36, 35, 32, 71}

    Returns: 138

  102. {0, 1, 0, 0 }

    {0, 0, 1, 0 }

    Returns: 0

  103. {0, 1, 100, 0 }

    {0, 1, 1, 1 }

    Returns: 3

  104. {37, 11, 3, 3 }

    {3, 0, 92, 25 }

    Returns: 54

  105. {5, 0, 0, 0 }

    {0, 4, 2, 0 }

    Returns: 5

  106. {5, 2, 2, 2 }

    {3, 3, 3, 3 }

    Returns: 11

  107. {0, 0, 0, 1 }

    {0, 0, 0, 0 }

    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: