Eat Or Not?
Practice
4.2 (18 votes)
Approved
Data structures
Easy
Greedy algorithms
Hiring
Ready
Problem
88% Success 6712 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 \(i^{th}\) line denotes the number of VItamins, Carbs, Fats and Proteins in the\(i^{th}\) fruit.

Output Format:

Print the required answer on a single line

Constraints:

\( 10 \le V_{des} ,C_{des}, P_{des}, F_{des} \le 1000 \)

\( 1 \le N \le 20 \)

\( 10 \le V[i],C[i],F[i],P[i] \le 1000\),

where \(V[i],C[i],F[i],P[i]\) denote the number of VItamins, Carbs,Fats and Proteins in the \(i^{th}\) fruit respectively .

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
7 votes
Tags:
Greedy AlgorithmsAlgorithmsBasics of Greedy AlgorithmsGreedy algorithm
Points:20
390 votes
Tags:
ApprovedBrute-force searchEasyGreedy AlgorithmsOpenSorting
Points:20
71 votes
Tags:
AlgorithmsEasyGreedy Algorithms