SantaClaus
SRM 275 · 2005-11-30 · by dgoodman
Problem Statement
Specifically he has estimated the intrinsic value of each present to each person. He wants software to determine if there is a group of people whose total value would be increased by redistributing the gifts within the group. Some people might end up with a worse present, but the total value is what Santa must consider. If such a group exists, Santa would like to know the size of the smallest such group, and how much the total value of their presents can be increased by.
The intrinsic value of the presents to each person is given in a
The original intent of Santa was to give the first present to the first person, the second present to the second person, etc.
Create a class SantaClaus that contains a method exchange that is given the
Constraints
- value will contain n elements, where n is between 2 and 50 inclusive.
- Each element of value will contain n characters, each being an uppercase letter 'A'-'Z'.
{"ABCDE","ABCDE","ABCDE","ABCDE","ABCDE"}
Returns: {0, 0 }
Each present has the same value to everybody, so there is no way to increase the total value by reassigning the presents.
{"ABC","BCD","ZAB"}
Returns: {2, 26 }
The third person would really like the first present. So we could exchange presents between the first person and the third person. Previously, the values were 1 (first person) + 2 (third person) = 3. After the exchange the values become 3 (first person) + 26 (third person) = 29. So the net gain is 29-3 = 26.
{"BCAAA","ADEAA","AAXYA","AAAKL","EAAAD"}
Returns: {3, 1 }
The first, fourth, and fifth persons can exchange presents, giving up values of 'B', 'K', and 'D' and acquiring values of 'A', 'L', and 'E'. The first person loses net value of 1, but each of the others gains 1.
{"VWAAA","ADEAA","AAXYA","AAAKL","EAAAD"}
Returns: {5, 5 }
{"VWAAA","ADEAA","AAXYA","AAAKL","EAAZD"}
Returns: {2, 23 }
Submissions are judged against all 29 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SantaClaus with a public method vector<int> exchange(vector<string> value) · 29 test cases · 2 s / 256 MB per case