← 返回 doordash 的题目列表Shopping Cart with Promotions
类型:online_judge
You need to write a function to calculate the final payment amount for a shopping cart. The cart contains several items, each with a price and a total amount, plus a fixed shipping cost. You have a list of promotions available in two types: percentage discount (note: does not apply to shipping) and fixed amount discount. Your task is to determine the biggest discount applicable and return the final payment amount.
Interface:
def calculate_final_amount(prices: List[float], shipping_cost: float, promotions: List[Dict[str, float]]) -> float:
prices: List of prices for each item.
shipping_cost: Fixed shipping cost.
promotions: List of promotions, each is a dictionary with a type ('percentage' or 'fixed') and a value. The value of percentage promotions is the discount percentage, and for fixed amount promotions, it is the amount to be deducted.
Return the final payment amount.
Note
Ensure the final amount after discount is not negative.
Handle all edge cases.
Example
prices = [10.0, 20.0, 30.0]
shipping_cost = 5.0
promotions = [{'type': 'percentage', 'value': 10}, {'type': 'fixed', 'value': 5}]
calculate_final_amount(prices, shipping_cost, promotions) # Should return 58.0
Example
Input
10.0 20.0 30.0
5.0
percentage 10
fixed 5