Connection Status:
Competition Arena > SupermarketDiscount
SRM 334 · 2007-01-13 · by Andrew_Lazarev · Brute Force
Class Name: SupermarketDiscount
Return Type: int
Method Name: minAmount
Arg Types: (vector<int>)
Problem Statement

Problem Statement

Three girls are shopping at a supermarket. The supermarket is having a sale: "Spend $50 or more in a single transaction and get $10 off." The girls realize that if they combine their purchases, they might be able to pay less than if they each pay separately. For example, if they are buying a total of $46, $62 and $9 worth of goods, respectively, they can combine the $46 and $9 totals and make two purchase transactions ($55 and $62) to get $20 off.

You will be given a int[] goods, each element of which is the total cost of the goods purchased by one of the girls. Return the minimal total cost required to purchase all the goods. The girls are willing to combine their purchases as described above, but no girl is willing to split up her goods across multiple transactions.

Constraints

  • goods will contain exactly 3 elements.
  • Each element of goods will be between 1 and 99, inclusive.
Examples
0)
{46, 62, 9}
Returns: 97

The example from the problem statement.

1)
{50, 62, 93}
Returns: 175

The best decision is to pay separately.

2)
{5, 31, 15}
Returns: 41

The only way to get the discount is to combine all three purchases into one transaction.

3)
{5, 3, 15}
Returns: 23

The girls have no chance of getting the discount.

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

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

Coding Area

Language: C++17 · define a public class SupermarketDiscount with a public method int minAmount(vector<int> goods) · 130 test cases · 2 s / 256 MB per case

Submitting as anonymous