Shopping Plans
Time limit2sMemory limit512 MB
Given items with types and costs and a count range per type, find the K cheapest subsets whose per-type counts fall within their ranges.
- Level
Hard9 of 10
- Topics
- Divide and conquer, Heap, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
You are shopping from a store that sells a total of items. The -th item has a type , which is an integer between and . A feasible shopping plan is a subset of these items such that for every type , the number of items of type is in the interval .
The -th item in the store has a cost of , and the cost of a shopping plan is the sum of the costs of the items in the plan. Find the costs of the cheapest feasible shopping plans. If two different shopping plans have the same cost, they are counted separately in the output.
Input
The first line contains three space-separated integers , , and (). The next lines each contain two space-separated integers and (, ). The next lines each contain two space-separated integers and ().
Output
Output lines. On the -th line, output the cost of the -th cheapest feasible shopping plan, or if there are fewer than feasible shopping plans.
Hint
A feasible shopping plan must combine exactly one item with a cost in with exactly one item with a cost in .