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
{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.
{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.
{0, 0, 0, 0}
{100, 100, 100, 100}
Returns: 0
With no blood banks available there is nothing the girl can do.
{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.
{0, 0, 0, 0}
{0, 0, 0, 0}
Returns: 0
{100, 100, 100, 100}
{0, 0, 0, 0}
Returns: 0
{0, 0, 0, 0}
{100, 100, 100, 100}
Returns: 0
{100, 100, 100, 100}
{100, 100, 100, 100}
Returns: 400
{40, 30, 20, 10}
{10, 20, 30, 40}
Returns: 100
{1, 3, 3, 7}
{4, 2, 4, 2}
Returns: 8
{4, 2, 4, 2}
{1, 3, 3, 7}
Returns: 12
{13, 50, 4, 5}
{13, 42, 0, 17}
Returns: 72
{17, 11, 11, 3}
{13, 10, 10, 10}
Returns: 42
{13, 42, 17, 69}
{5, 39, 19, 77}
Returns: 140
{66, 47, 58, 56}
{38, 36, 75, 55}
Returns: 204
{38, 58, 83, 4}
{47, 30, 0, 38}
Returns: 106
{5, 6, 57, 42}
{25, 66, 83, 22}
Returns: 90
{85, 79, 0, 36}
{16, 73, 42, 53}
Returns: 184
{24, 60, 80, 0}
{48, 40, 2, 74}
Returns: 140
{23, 42, 15, 26}
{77, 63, 81, 89}
Returns: 106
{57, 62, 7, 0}
{78, 91, 57, 71}
Returns: 126
{100, 27, 100, 37}
{44, 59, 1, 34}
Returns: 138
{7, 16, 26, 73}
{89, 77, 60, 39}
Returns: 88
{3, 37, 25, 68}
{58, 98, 98, 82}
Returns: 133
{30, 58, 9, 100}
{8, 36, 21, 2}
Returns: 67
{30, 79, 22, 45}
{85, 48, 22, 33}
Returns: 133
{30, 94, 11, 38}
{49, 61, 31, 85}
Returns: 173
{78, 56, 48, 75}
{6, 84, 85, 100}
Returns: 257
{56, 30, 25, 19}
{99, 51, 31, 8}
Returns: 119
{57, 47, 34, 6}
{60, 93, 55, 21}
Returns: 144
{14, 59, 30, 26}
{60, 1, 62, 61}
Returns: 106
{97, 90, 85, 2}
{53, 19, 61, 91}
Returns: 224
{4, 71, 59, 49}
{10, 46, 29, 59}
Returns: 138
{16, 94, 35, 22}
{2, 72, 26, 6}
Returns: 106
{44, 68, 57, 44}
{82, 93, 1, 14}
Returns: 127
{96, 17, 48, 22}
{57, 35, 0, 11}
Returns: 103
{72, 7, 74, 53}
{61, 78, 79, 56}
Returns: 206
{61, 10, 67, 39}
{37, 27, 35, 87}
Returns: 177
{80, 98, 35, 0}
{91, 31, 65, 4}
Returns: 150
{51, 68, 51, 73}
{18, 44, 63, 21}
Returns: 146
{29, 80, 14, 78}
{65, 46, 65, 1}
Returns: 90
{3, 22, 6, 89}
{0, 17, 81, 90}
Returns: 116
{61, 5, 6, 80}
{36, 66, 21, 68}
Returns: 140
{20, 19, 99, 77}
{57, 85, 14, 48}
Returns: 101
{87, 4, 13, 36}
{18, 46, 96, 14}
Returns: 118
{3, 3, 40, 90}
{60, 22, 99, 72}
Returns: 118
{36, 76, 57, 2}
{39, 98, 54, 13}
Returns: 171
{14, 58, 17, 60}
{36, 56, 31, 29}
Returns: 116
{23, 72, 74, 86}
{76, 90, 15, 53}
Returns: 163
{41, 86, 34, 4}
{22, 56, 35, 39}
Returns: 152
{79, 80, 53, 41}
{13, 37, 44, 28}
Returns: 122
{100, 24, 50, 1}
{69, 67, 63, 70}
Returns: 175
{11, 98, 25, 11}
{50, 82, 97, 18}
Returns: 136
{98, 96, 46, 46}
{53, 49, 69, 71}
Returns: 242
{76, 60, 50, 45}
{68, 63, 61, 66}
Returns: 231
{10, 85, 93, 47}
{79, 47, 33, 43}
Returns: 133
{11, 75, 91, 2}
{61, 7, 78, 27}
Returns: 123
{9, 90, 67, 34}
{18, 96, 51, 90}
Returns: 200
{18, 0, 37, 50}
{24, 0, 80, 54}
Returns: 105
{82, 92, 86, 61}
{76, 5, 84, 10}
Returns: 175
{58, 4, 29, 55}
{30, 96, 98, 21}
Returns: 112
{86, 33, 24, 78}
{25, 73, 19, 31}
Returns: 148
{16, 92, 45, 14}
{47, 35, 72, 8}
Returns: 104
{20, 97, 71, 64}
{31, 46, 67, 50}
Returns: 183
{55, 43, 34, 48}
{78, 39, 75, 100}
Returns: 180
{38, 13, 31, 6}
{38, 58, 27, 7}
Returns: 85
{78, 22, 63, 30}
{15, 36, 73, 66}
Returns: 190
{18, 47, 75, 9}
{77, 3, 28, 67}
Returns: 116
{73, 55, 50, 48}
{40, 46, 9, 72}
Returns: 167
{94, 62, 42, 52}
{8, 30, 18, 22}
Returns: 78
{0, 22, 12, 87}
{31, 88, 13, 92}
Returns: 121
{19, 32, 38, 96}
{65, 54, 7, 22}
Returns: 80
{48, 6, 11, 34}
{53, 23, 58, 76}
Returns: 99
{93, 74, 30, 61}
{30, 89, 36, 21}
Returns: 176
{25, 21, 3, 75}
{57, 96, 76, 66}
Returns: 115
{26, 45, 76, 40}
{57, 15, 5, 89}
Returns: 135
{11, 25, 3, 57}
{99, 17, 96, 59}
Returns: 90
{41, 9, 100, 93}
{87, 81, 36, 37}
Returns: 123
{6, 84, 4, 8}
{73, 20, 28, 28}
Returns: 58
{65, 10, 18, 38}
{64, 24, 25, 65}
Returns: 131
{56, 93, 48, 46}
{15, 99, 54, 67}
Returns: 235
{87, 8, 47, 80}
{80, 3, 63, 29}
Returns: 166
{6, 23, 74, 64}
{67, 56, 85, 1}
Returns: 104
{9, 44, 94, 63}
{22, 87, 89, 82}
Returns: 210
{57, 74, 17, 70}
{17, 90, 15, 47}
Returns: 169
{91, 25, 63, 66}
{6, 94, 77, 74}
Returns: 245
{84, 28, 57, 73}
{5, 79, 86, 62}
Returns: 231
{88, 31, 68, 45}
{86, 78, 28, 25}
Returns: 172
{17, 79, 96, 45}
{64, 56, 70, 15}
Returns: 158
{9, 75, 12, 5}
{73, 3, 49, 92}
Returns: 101
{30, 15, 78, 62}
{40, 8, 72, 32}
Returns: 142
{91, 15, 94, 85}
{2, 12, 92, 73}
Returns: 179
{59, 42, 33, 78}
{87, 13, 66, 73}
Returns: 178
{73, 91, 21, 59}
{50, 35, 92, 60}
Returns: 189
{65, 38, 3, 64}
{29, 1, 24, 8}
Returns: 62
{15, 96, 46, 69}
{17, 49, 2, 73}
Returns: 139
{89, 49, 81, 20}
{13, 1, 73, 56}
Returns: 143
{8, 26, 11, 8}
{1, 75, 83, 8}
Returns: 53
{28, 17, 80, 63}
{27, 0, 9, 45}
Returns: 81
{42, 57, 60, 14}
{11, 29, 50, 38}
Returns: 128
{26, 78, 6, 35}
{36, 35, 32, 71}
Returns: 138
{0, 1, 0, 0 }
{0, 0, 1, 0 }
Returns: 0
{0, 1, 100, 0 }
{0, 1, 1, 1 }
Returns: 3
{37, 11, 3, 3 }
{3, 0, 92, 25 }
Returns: 54
{5, 0, 0, 0 }
{0, 4, 2, 0 }
Returns: 5
{5, 2, 2, 2 }
{3, 3, 3, 3 }
Returns: 11
{0, 0, 0, 1 }
{0, 0, 0, 0 }
Returns: 0