DiffPush Tier Dynamic Programming · DP on Stocks O(n*k) · O(k)
The regulator now issues the broker a quota of k lock-release cycles per quarter. The fleet's scheduling terminal must allocate those k cycles across the fee curve to harvest the largest combined spread, never overlapping two cycles. When the quota exceeds the number of profitable swings, the cap effectively disappears.
Input: An integer k and an array prices where prices[i] is the fee on hour i.
Output: Return the maximum profit using at most k non-overlapping buy-sell transactions.
0 <= k <= 1001 <= len(prices) <= 10000 <= prices[i] <= 1000Input: {"k":2,"prices":[2,4,1]}
Output: 2
The only climb is 2 to 4; one cycle captures it all.
Input: {"k":2,"prices":[3,2,6,5,0,3]}
Output: 7
(2 to 6) plus (0 to 3) — both cycles inside the quota.