#t362. 营养膳食
营养膳食
Nutritious Diet
Problem Description
Mr. L is carrying out his weight-gain plan.
To gain weight, Mr. L wants to eat more fat. However, he cannot eat only high-fat food, or he would lack other nutrients.
Mr. L's research shows that a truly nutritious diet forbids eating more than a certain number of servings of a given food type at once. For example, in one meal, meat should not exceed serving, fish should not exceed serving, eggs should not exceed serving, and vegetables should not exceed servings.
Mr. L wants to eat as much fat as possible under a nutritious diet, but of course his appetite is also limited.
Input Format
The first line contains three positive integers : Mr. L can eat at most servings per meal, there are kinds of food to choose from, and these foods are divided into categories.
The second line contains positive integers not exceeding : the maximum number of servings allowed for categories to .
The following lines each contain two positive integers: the fat index and the category of that food.
Output Format
One number: the maximum total fat index Mr. L can eat.
Sample Input
6 6 3
3 3 2
15 1
15 2
10 2
15 2
10 2
5 3
Sample Output
60
Constraints
For of the data: , , , , .