Lily's Savory Blend
Practice
5 (1 votes)
Algorithms
Dynamic programming
3d dynamic programming
Problem
81% Success 139 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Lily wants to make a special type of sandwich spread called "Savory Blend." To create this spread, she needs to mix two main ingredients, Ingredient \(A\) and Ingredient \(B\), in a specific ratio of \(M_A:M_B\).

Unfortunately, Lily doesn't have any of these ingredients in her kitchen, so she decides to go shopping at a local grocery store. The store offers \(N\) different varieties of pre-packaged ingredients. Each package contains a certain amount of Ingredient \(A_i\) grams and Ingredient \(B_i\)grams, and it's priced at \(C_i\) rupees.

Lily is determined to create her Savory Blend, and she commits to using all the ingredients she purchases. However, she wants to minimize her spending. Your task is to help Lily figure out the minimum amount of money she needs to spend to make her Savory Blend.

If it's impossible to achieve the desired blend with the available packages, return \(-1\).

Input Format:

The first line of input contains \(3\) integers: \(N\)\(M_a \) and \(M_b\).

Then there are \(N\) lines describing each package. Each line contains  \(3\) integers: \(A_i\),  \(B_i\)  and  \(C_i\) 

Output Format:

Print the minimum amount of money required to make the Savory Blend. If it is not possible to make it, print \(-1\) instead.

Constraints:

\(1 \leq N \leq 40 \\ 1 \leq A_i,B_i \leq10\\ 1 \leq C_i \leq100 \\ 1 \leq M_A,M_B \leq 10 \\ gcd(M_A,M_B)=1 \)

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:30
Points:30
1 votes
Tags:
AlgorithmsMedium
Points:30
1 votes
Tags:
Dynamic ProgrammingAlgorithmsC++3D dynamic programming