#P2569. [SCOI2010] 股票交易

    ID: 1586 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2010四川各省省选单调队列队列

[SCOI2010] 股票交易

Description

Recently, lxhgww\text{lxhgww} has gotten into stock investing again. After a period of observation and learning, he summarized some patterns in stock prices.

Over time, lxhgww\text{lxhgww} predicted the movement of a certain stock for the next TT days. On day ii, the buy price per share is APiAP_i, and the sell price per share is BPiBP_i (the data guarantees that for every ii, APiBPiAP_i \geq BP_i). However, trading cannot be unrestricted each day, so the exchange stipulates that in a single buy on day ii, you can purchase at most ASiAS_i shares, and in a single sell on day ii, you can sell at most BSiBS_i 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 WW days in between. That is, if a transaction occurs on day ii, then from day i+1i+1 to day i+Wi+W (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 MaxP\text{MaxP}.

Before day 11, lxhgww\text{lxhgww} has a large amount of cash (consider it as unlimited cash), but no stock. Of course, after TT days, lxhgww\text{lxhgww} wants to earn as much money as possible. Smart programmers, can you help him?

Input Format

The first line of input contains 33 integers: TT, MaxP\text{MaxP}, and WW.

The next TT lines describe the stock data. The ii-th line corresponds to day ii and contains 44 integers, namely APi, BPi, ASi, BSiAP_i,\ BP_i,\ AS_i,\ BS_i.

Output Format

Output a single number: the maximum amount of money lxhgww\text{lxhgww} 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, 0W<T500 \leq W < T \leq 50, 1MaxP501 \leq \text{MaxP} \leq 50.
  • For 50% of the testdata, 0W<T20000 \leq W < T \leq 2000, 1MaxP501 \leq \text{MaxP} \leq 50.
  • For 100% of the testdata, 0W<T20000 \leq W < T \leq 2000, 1MaxP20001 \leq \text{MaxP} \leq 2000.
  • For all testdata, 1BPiAPi10001 \leq BP_i \leq AP_i \leq 1000, 1ASi,BSiMaxP1 \leq AS_i,BS_i \leq \text{MaxP}.

Translated by ChatGPT 5