A store is having a big sale.
If your price reaches $199 or more, you can reduce it by $100.
You can buy each product only once.
Here's an example list of products: (in order to simplify, the names of the products are represented by letters)
+------+-------+
| name | price |
+------+-------+
| A | 26.9 |
| B | 24.9 |
| C | 49.9 |
| D | 28.9 |
| E | 14.9 |
| F | 16.9 |
| G | 19.9 |
| H | 19 |
| I | 14.9 |
| J | 14.9 |
| K | 26.9 |
+------+-------+
Input
- A list of product price, such as the above example.
N
the item list size10 <= N <= 100
X
a price
Output
The best shopping strategy to save money. Find out the least expensive purchase list with a total price of more than X
,
and output:
- The most appropriate total price (before deduction), for the data above,
X
= $199, and the most appropriate total price is199.2
Notes
- Your code can be a function (method) or a full working program.
- Make your algorithm as fast as possible (less time complexity)!
- If codes have the same time complexity, the one which uses less space wins.
code-golf
but many others exist). I'd also recommend to include the solution for the given example and add a few other test cases. Also, can a product be purchased more than once? Is the total price supposed to be displayed before or after discount? \$\endgroup\$fastest-algorithm
(the tag you've chosen) doesn't meanfastest-code
(like your description suggests). I personally think thatfastest-algorithm
is indeed a better option here, so you'd rather edit the description than update the tag. \$\endgroup\$