1558 - Buns

Time Limit : 1 Second

Memory Limit : 128 MB

Submission: 104

Solved: 17

Description
Jianhe25 is a baker. The only food he can cook is buns with creams. Jianhe25 want to sell buns.



Jianbe25 has n grams of dough and m different cream types which number is from 1 to m. Jianhe25 knows that he has ai grams

left of the i-th cream.



To cook a bun with the i-th cream, Jianhe25 must use exactly  bi grams of cream i and ci grams of dough. Such bun can be

sold for $ di .



He also can make buns without creams which requires c0 grams of dough. And this creams can be sold for $ d0. So Jianhe25 can

cook any number of buns with different creams unless he runs out of dough and the creams. Jianhe25 throws away all excess

material left after baking.



Find the maximum money Jianhe25 can earn.

Input
Several test cases. The first line contains four integers nmc0 and d0 (1 ≤ n ≤ 1000, 1 ≤ m ≤ 10, 1 ≤ c0, d0 ≤ 100). Each of the following m lines contains four integers. The i-th line contains numbers aibici and di (1 ≤ ai, bi, ci, di ≤ 100).

Output
For each test case print one line ---- the the maximum number of money Jianhe25 can earn.

sample input
10 2 2 1
7 3 2 100
12 3 1 10

100 1 25 50
15 5 20 10
sample output
241
200
hint
You can use this form of code to deal with several test cases.
 
while (scanf(...) != EOF)
{
//Your codes here.
}

or

while (cin >> input)
{
//your code here
}
source
The 6th ACM Programming Contest of HUST
© 2015 HUST ACMICPC TEAM. All Right Reserved.