Buying Hay
InterviewTime limit1sMemory limit128 MB
Given N package types with unlimited supply, each weighing P_i and costing C_i, find the minimum total cost to buy at least H pounds of hay.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Math, Brute force
- Solved
- No attempts yet
Problem
Farmer John is running low on supplies and needs to buy at least () pounds of hay for his cows.
There are () hay suppliers, conveniently numbered through . Supplier sells packages that each contain () pounds of hay at a price of () dollars. Every supplier has an unlimited number of packages, and each package must be bought whole (packages cannot be split).
Help Farmer John find the minimum cost required to buy at least pounds of hay.
Input
- Line 1: Two space-separated integers and .
- Lines 2 to : Line contains two space-separated integers and for supplier .
Output
- Line 1: A single integer, the minimum cost Farmer John must pay to obtain at least pounds of hay.
Hint
For instance, buying three packages from the second supplier ( pounds each at dollars) yields pounds for a total cost of dollars.