#P2569. [SCOI2010] 股票交易
[SCOI2010] 股票交易
Description
Recently, has gotten into stock investing again. After a period of observation and learning, he summarized some patterns in stock prices.
Over time, predicted the movement of a certain stock for the next days. On day , the buy price per share is , and the sell price per share is (the data guarantees that for every , ). However, trading cannot be unrestricted each day, so the exchange stipulates that in a single buy on day , you can purchase at most shares, and in a single sell on day , you can sell at most shares.
In addition, the exchange has two more rules. To avoid excessive trading, the exchange requires that between any two transactions (a buy or a sell on any day counts as one transaction), there must be at least days in between. That is, if a transaction occurs on day , then from day to day (inclusive), no transactions are allowed. Also, to prevent monopolies, the exchange mandates that at any time, the number of shares a person holds cannot exceed .
Before day , has a large amount of cash (consider it as unlimited cash), but no stock. Of course, after days, wants to earn as much money as possible. Smart programmers, can you help him?
Input Format
The first line of input contains integers: , , and .
The next lines describe the stock data. The -th line corresponds to day and contains integers, namely .
Output Format
Output a single number: the maximum amount of money can earn.
5 2 0
2 1 1 1
2 1 1 1
3 2 1 1
4 3 1 1
5 4 1 1
3
Hint
- For 30% of the testdata, , .
- For 50% of the testdata, , .
- For 100% of the testdata, , .
- For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号