## CCO '20 P6 - Shopping Plans

View as PDF

Points: 30 (partial)
Time limit: 2.0s
Memory limit: 1G

Author:
Problem type
##### Canadian Computing Olympiad: 2020 Day 2, Problem 3

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 all types , 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 items in the plan. You are interested in the possible costs of feasible shopping plans. Find the costs of the cheapest feasible shopping plans. Note that if there are two different shopping plans with the same cost, they should be counted separately in the output.

#### Input Specification

The first line consists of three space-separated integers , , and . lines follow, the -th of which contains two space-separated integers and . lines follow, the -th of which contains two space-separated integers and .

For 5 of the 25 available marks, and .

For an additional 5 of the 25 available marks, and .

For an additional 5 of the 25 available marks, .

For an additional 5 of the 25 available marks, .

#### Output Specification

Output lines. On the -th line, output the cost of the -th cheapest feasible shopping plan, if one exists, or -1 if there are fewer than feasible shopping plans.

#### Sample Input 1

5 2 7
1 5
1 3
2 3
1 6
2 1
1 1
1 1

#### Output for Sample Input 1

4
6
6
7
8
9
-1

#### Explanation of Output for Sample Input 1

A feasible shopping plan must combine exactly one item with a cost in with exactly one item with a cost in .