Connection Status:
Competition Arena > EllysBlood
TCO20 North America Qualifier · 2020-09-19 · by espr1t · Greedy
Class Name: EllysBlood
Return Type: int
Method Name: getMax
Arg Types: (vector<int>, vector<int>)
Problem Statement

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.

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
0)
{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.

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

2)
{0, 0, 0, 0}
{100, 100, 100, 100}
Returns: 0

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

3)
{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.

4)
{0, 0, 0, 0}
{0, 0, 0, 0}
Returns: 0

Submissions are judged against all 107 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class EllysBlood with a public method int getMax(vector<int> have, vector<int> need) · 107 test cases · 2 s / 256 MB per case

Submitting as anonymous