1152: Shennong tastes all kinds of herbs

内存限制:32 MB 时间限制:1.000 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:2 通过率:100%

题目描述

Shennong asked Chisongzi for advice on the way of longevity. Chisongzi taught Shennong how to choose fairy grass and prolong life. Chisongzi took Shennong to Shennongjia and told him: "there are fairy grasses on the mountain. It takes some time to pick each grass, and each grass also has its own use value. There are also three rare grasses on the mountain, which are used independently and have strange poison. However, any two rare grasses used at the same time can be equivalent to a fairy grass, and its use value is the product of the value of two rare grasses, but each rare grass can not be reused. I will give you a period of time. During this period, you should pick some grasses as much as possible to maximize the total use value of the grasses.

 

Shennong acted immediately, tasted all kinds of grass and fulfilled his mission. Do you know how Shennong accomplished this task?

输入格式

The input has multiple cases (no more than 100) of test data.

 

The first line of each test cases is two positive integers T1 ≤ T ≤ 1000 and M1 ≤ M ≤ 100, representing the time used to collect grass and the number of fairy grass on Shennongjia. Next, there are M lines. Each line contains two positive integers t and v (1 ≤ t, v ≤ 100), representing the time of picking the fairy grass and the value of the fairy grass respectively. The last three lines are the picking time a (1 ≤ a ≤ 100) and use value b (- 100 ≤ b < 0) of three rare grasses.

 

The end of input will be represented by a line of test case where T and M are equal to 0. This test case should not be processed.

输出格式

Each test case outputs a line, which is an integer, indicating the maximum total use value of fairy grass that can be collected in T time.

输入样例 复制

70 3
71 100
68 3
1 2
1 -2
1 -3
1 -4
0 0

输出样例 复制

15