Eat Or Not?

4.2

18 votes
Approved, Data Structures, Easy, Greedy Algorithms, Hiring, Ready
Problem

Our friend Monk has decided to go on a diet in order to improve his Eating Habits. One of his friends told him that Monk should eat a fixed amount of Vitamins, Carbs, Fats and Proteins daily in order to loose weight. Monk wants to strictly follow this regime.

There are N fruits kept in Monk's Fridge. Each fruit contains a fixed amount of Vitamins, Carbs, Fats and Proteins. Now, Monk wants to know if upon selecting any subset of fruits from the fridge, the sum of their Vitamins, Carbs, Fats and Proteins is individually equal to their corresponding equivalent amount that Monk desires to eat. For example, if Monk selects Fruits i, j and k, then the sum of the vitamins of these 3 fruits should be equal to the amount of vitamins Monk wants to eat and so on for Carbs, Fats and Protiens as well.

If there exists such a subset to satisfy Monk's demands, print "YES"(without quotes), else print "NO"(without quotes).

Input Format:

The First line contains 4 space separated integers denoting the amount of Vitamins, Carbs, Fats and Protiens that Monk desires to eat. The next line contains a single integer N denoting the number of Fruits in Monk's Fridge. Each of the next N lines contains 4 space separated integers, where the ith line denotes the number of VItamins, Carbs, Fats and Proteins in theith fruit.

Output Format:

Print the required answer on a single line

Constraints:

10Vdes,Cdes,Pdes,Fdes1000

1N20

10V[i],C[i],F[i],P[i]1000,

where V[i],C[i],F[i],P[i] denote the number of VItamins, Carbs,Fats and Proteins in the ith fruit respectively .

Sample Input
100 100 100 100
4
50 50 50 50
50 50 50 50
50 50 50 50
50 50 50 50
Sample Output
YES
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here, selecting any two pairs of fruits shall lead to satisfaction of Monk's demands.

Contributers:
Editor Image

?