#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 xx days.

Input Format

The first line contains two integers xx and nn, which represent the number of days Xiao Lan needs to eat chocolate and the number of chocolate types.

The next nn lines describe the chocolates on the shelf. The ii-th line contains three integers aia_i, bib_i, and cic_i, meaning that the unit price of the ii-th type is aia_i, the shelf life has bib_i days remaining (it can be eaten within the next bib_i days from now), and the quantity is cic_i.

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 xx days, output 1-1.

10 3
1 6 5
2 7 3
3 10 10
18

Hint

Sample Explanation

One optimal plan is to buy 55 bars of type 11, 22 bars of type 22, and 33 bars of type 33. Eat type 11 for the first 55 days, type 22 on days 66 and 77, and type 33 from day 88 to day 1010.

Constraints and Notes

For 30%30\% of the testdata, n,x1000n, x \le 1000.

For all testdata, 1n,x1051 \le n, x \le 10^5, 1ai,bi,ci1091 \le a_i, b_i, c_i \le 10^9.

Lanqiao Cup 2021 National Contest, Group C, Problem I.

Translated by ChatGPT 5