Life Savings
InterviewTime limit2sMemory limit512 MB
Compare the savings from one 20%-style whole-purchase coupon against the best way to spend two one-item coupons on two of three items, then print the winning plan and its savings.
- Level
Easy2 of 10
- Topics
- Brute force, Math, Implementation, Greedy
- Solved
- No attempts yet
Problem
Stanley is careful with money. He lives simply and counts every penny he spends. The few people who call him a friend describe him as thrifty. He is a miser.
Stan never goes shopping without coupons, and right now he has a problem at the checkout. He wants three items with list prices of $100, $50 and $40. He holds three coupons. One takes 20% off the entire purchase and cannot be combined with any other coupon. The other two are one-item coupons, one for 30% off and one for 25% off, and he may use them together on two different items. Stan cannot tell whether the single whole-purchase coupon beats the two one-item coupons used together, and the line behind him is getting impatient. Work out for Stan which choice he should make and how much it saves.
Input
The input has two lines.
The first line has the list prices , , of the three items, separated by spaces. ()
The second line has the discount percentages , , of the three coupons, separated by spaces. () Coupon applies to the whole purchase and cannot be combined with any other coupon. Coupons and each apply to a single item, and the two may be used on two different items at the same time.
All values are integers. Prices are in dollars and discounts are in percent.
Output
Compare the amount saved by coupon alone with the largest amount that and can save on two different items. If the first amount is larger, print one. Otherwise print two. Then print a single space and the amount saved by the plan you printed. If the two amounts are equal, print two. Write the amount with exactly two digits after the decimal point and no dollar sign. Every possible saving is a whole number of cents.