Connection Status:
Competition Arena > BasketsWithApples
SRM 285 · 2006-01-24 · by Andrew_Lazarev · Brute Force, Simple Math
Class Name: BasketsWithApples
Return Type: int
Method Name: removeExcess
Arg Types: (vector<int>)
Problem Statement

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 int[] apples where the i-th element of apples is the number of apples in the i-th basket. Return the number of apples remaining after the procedure described above is performed.

Constraints

  • apples will contain between 1 and 50 elements, inclusive.
  • Each element in apples will be between 0 and 1000, inclusive.
Examples
0)
{1, 2, 3}
Returns: 4

We should remove the first basket and leave two apples in each of the two remaining baskets.

1)
{5, 0, 30, 14}
Returns: 30

We should leave only the third basket.

2)
{51, 8, 38, 49}
Returns: 114
3)
{24, 92, 38, 0, 79, 45}
Returns: 158
4)
{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.

Coding Area

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

Submitting as anonymous