Vitamins
InterviewTime limit2sMemory limit1024 MB
Given N tablets with their vitamin C, vitamin D, and price, find the minimum cost to get at least C mg of vitamin C and D mg of vitamin D.
- Level
Medium5 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
Winter is a season when it is important to get enough vitamins. Adomas knows this and walks into the pharmacy Vitaminų Pasaulis, which sells many kinds of multivitamin tablets. Taking too many vitamins can be harmful, so the pharmacy sells at most one tablet of each kind to a single customer.
Adomas is most interested in vitamin C, which strengthens the immune system, and vitamin D, which is essential for bones and teeth. The shop has so many different tablets that Adomas gets confused.
The amount of vitamin C and vitamin D in each tablet is known, and so is the price of each tablet. Find the minimum amount Adomas must pay to buy at least milligrams of vitamin C and at least milligrams of vitamin D.
Input
The first line contains three integers: the number of tablets , and the amounts and that Adomas wants.
Each of the next lines describes one tablet. It contains the amount of vitamin C , the amount of vitamin D (in milligrams), and the price of the tablet (in cents). All numbers are integers.
Output
Print one integer: the minimum number of cents Adomas must spend to buy at least milligrams of vitamin C and at least milligrams of vitamin D.
A solution always exists, because buying all the tablets gives Adomas at least the required amounts.