Connection Status:
Competition Arena > Oranges
Rookie SRM 15 · 2022-07-04 · by erinn · Simple Math
Class Name: Oranges
Return Type: int
Method Name: maximum
Arg Types: (vector<int>)
Problem Statement

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?

Constraints

  • bags will contain between 1 and 50 elements, inclusive.
  • Each element of bags will be between 1 and 10, inclusive.
Examples
0)
{ 1, 2, 3 }
Returns: 6

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

1)
{ 5, 2, 5, 3 }
Returns: 10

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

2)
{ 3 }
Returns: 3

There's only one bag to take.

3)
{ 4, 4, 4, 4, 4, 4, 4 }
Returns: 4

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

4)
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Returns: 55

Submissions are judged against all 6 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Oranges with a public method int maximum(vector<int> bags) · 6 test cases · 2 s / 256 MB per case

Submitting as anonymous