TopCoder problem "BasketsWithApples" used in SRM 285 (Division II Level One)



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.

 

Definition

    
Class:BasketsWithApples
Method:removeExcess
Parameters:int[]
Returns:int
Method signature:int removeExcess(int[] apples)
(be sure your method is public)
    
 

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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6006

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8082&pm=6006

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force, Simple Math