Guitar Strings
Time limit2sMemory limit128 MB
Buy at least N guitar strings using packages of 6 or single strings from M brands at given prices, minimizing total cost.
- Level
Easy3 of 10
- Topics
- Brute force, Greedy, Math
- Solved
- No attempts yet
Problem
N strings on Kangto's guitar have snapped. New strings can be bought either as packages of 6 strings or individually in any quantity.
For each brand, the package price and single-string price are given. Find the minimum cost needed to buy at least N guitar strings.
Input
The first line contains the number of snapped strings N and the number of brands M. N is a positive integer at most 100, and M is a positive integer at most 50.
Each of the next M lines contains a brand's package price and single-string price, separated by a space. Every price is an integer between 0 and 1,000, inclusive.
Output
Print the minimum cost needed to buy at least N guitar strings.
Hint
There is no additional hint.