BasketsWithApples
SRM 285 · 2006-01-24 · by Andrew_Lazarev
Problem Statement
We have some baskets containing apples, and we would like to perform the following procedure in a way that maximizes the number of remaining apples. First, we discard some (or none) of the baskets completely. Then, if the remaining baskets do not all contain the same number of apples, we remove excess apples from the baskets until they do.
You will be given a
Constraints
- apples will contain between 1 and 50 elements, inclusive.
- Each element in apples will be between 0 and 1000, inclusive.
{1, 2, 3}
Returns: 4
We should remove the first basket and leave two apples in each of the two remaining baskets.
{5, 0, 30, 14}
Returns: 30
We should leave only the third basket.
{51, 8, 38, 49}
Returns: 114
{24, 92, 38, 0, 79, 45}
Returns: 158
{91,96,46,87}
Returns: 261
Submissions are judged against all 105 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BasketsWithApples with a public method int removeExcess(vector<int> apples) · 105 test cases · 2 s / 256 MB per case