Greeting Card Envelopes
Time limit3sMemory limit512 MB
Partition up to 15 card types into at most k groups so the total waste, where each group's waste uses one enclosing envelope sized to the group's max width and max height, is minimized.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, Brute force, Greedy
- Solved
- No attempts yet
Problem
Your greeting card company makes cards in many different sizes. The designers pick whatever dimensions they like, so there are many card types, and each type has a quantity you must manufacture.
You have to order envelopes for these cards. There is a hard limit on how many different envelope sizes you may order, and that limit can be smaller than the number of distinct card sizes. Every card has to fit inside some envelope, possibly with room to spare, and the wasted paper must be as small as possible. Waste is measured per card as the area of the envelope minus the area of the card. A card in a envelope wastes nothing, while the same card in a envelope wastes . You may not rotate a card to make it fit.
Suppose you have five card types: (5 cards), (10 cards), (20 cards), (8 cards), and (16 cards).
If you can buy only one envelope type, every card has to fit in it, so the smallest usable envelope is with area . The waste per card type is , , , , and . The total waste is .
If you can buy two envelope types, the best choice puts the , , and cards in envelopes and the and cards in envelopes, for a total waste of .
If you can buy five envelope types, you can match one envelope to each card type and waste nothing.
Given the list of card types and the number of envelope types you may buy, find the smallest possible amount of wasted paper.
Input
The first line contains two space separated integers and (), where is the number of card types and is the maximum number of envelope types you may order.
Each of the next lines contains three space separated integers , , and () describing one card type: is the width of these cards, is the height, and is the quantity.
Output
Print a single integer, the smallest possible total area of wasted paper.