#P8769. [蓝桥杯 2021 国 C] 巧克力
[蓝桥杯 2021 国 C] 巧克力
Problem Description
Xiao Lan likes eating chocolate very much, and he eats one bar of chocolate every day.
One day, Xiao Lan goes to the supermarket to buy some chocolate. There are many kinds of chocolate on the shelves. Each kind has its own price, quantity, and remaining shelf life in days. Xiao Lan only eats chocolate that has not expired. Please find the minimum cost for Xiao Lan to buy enough chocolate to last for days.
Input Format
The first line contains two integers and , which represent the number of days Xiao Lan needs to eat chocolate and the number of chocolate types.
The next lines describe the chocolates on the shelf. The -th line contains three integers , , and , meaning that the unit price of the -th type is , the shelf life has days remaining (it can be eaten within the next days from now), and the quantity is .
Output Format
Output one integer representing Xiao Lan's minimum cost. If there is no purchase plan that allows Xiao Lan to eat chocolate for days, output .
10 3
1 6 5
2 7 3
3 10 10
18
Hint
Sample Explanation
One optimal plan is to buy bars of type , bars of type , and bars of type . Eat type for the first days, type on days and , and type from day to day .
Constraints and Notes
For of the testdata, .
For all testdata, , .
Lanqiao Cup 2021 National Contest, Group C, Problem I.
Translated by ChatGPT 5