Statistics

Problem Statement for "Oranges"

Problem Statement

You are at the store purchasing some oranges, which are sold in bags. Each bag has a quantity of oranges in it, given in int[] bags. Assuming you buy no two bags with the same number of oranges, what is the maximum total oranges you end up purchasing?

Definition

Class:
Oranges
Method:
maximum
Parameters:
int[]
Returns:
int
Method signature:
int maximum(int[] bags)
(be sure your method is public)

Constraints

  • bags will contain between 1 and 50 elements, inclusive.
  • Each element of bags will be between 1 and 10, inclusive.

Examples

  1. { 1, 2, 3 }

    Returns: 6

    Since each bag has a different number of oranges, we can take all of them.

  2. { 5, 2, 5, 3 }

    Returns: 10

    We take a bag of 2, a bag of 3, and a bag of 5.

  3. { 3 }

    Returns: 3

    There's only one bag to take.

  4. { 4, 4, 4, 4, 4, 4, 4 }

    Returns: 4

    Since all the bags are the same size, we can only take one of them.

  5. { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    Returns: 55

  6. {5, 2, 5, 3 }

    Returns: 10


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: