#Q185. 「一本通 5.5 练习 4」股票交易
「一本通 5.5 练习 4」股票交易
Description
Original source: SCOI 2010
Recently, lxhgww has become obsessed with stock investment again. After some observation and learning, he has summarized certain patterns in stock market trends.
Through a period of observation, lxhgww predicted the trend of a certain stock over the next days. On the -th day, the stock's buying price per share is , and the selling price per share is (it is guaranteed that for each ). However, unlimited trading is not allowed each day, so the stock exchange stipulates that on the -th day, a single purchase can buy at most shares, and a single sale can sell at most shares.
Additionally, the stock exchange has two more rules. To prevent excessive trading, the stock exchange mandates that there must be at least days between two consecutive trades (a trade is defined as either a buy or a sell on a given day). That is, if a trade occurs on the -th day, then no trades can occur from the -th day to the -th day. Moreover, to avoid monopolization, the stock exchange also stipulates that at any time, the number of shares held by an individual cannot exceed .
Before the first day, lxhgww has a large sum of money (which can be considered infinite) but no stocks. Of course, after days, lxhgww wants to maximize his profit. Clever programmers, can you help him?
Input Format
The first line of input data contains three integers: .
The next lines represent the stock trends for the -th day. Each line contains four integers: .
Output Format
The output data consists of a single line containing a number, representing the maximum profit lxhgww can earn.
Sample 1
5 2 0
2 1 1 1
2 1 1 1
3 2 1 1
4 3 1 1
5 4 1 1
3
Data Range and Hints
For of the data, ;
For of the data, ;
For of the data, $0\le W\lt T\le 2000, 1\le \text{MaxP}\le 2000, 1\le BP_i\le AP_i\le 1000, 1\le AS_i, BS_i\le \text{MaxP}$.