You are given an integer array prices of length n, where prices[i] is the price of a stock on day i.
You are also given an integer cooldown and an integer array costs of length n. The value costs[k] is the total holding fee for a transaction in which the stock is held for exactly k days.
You may perform any number of transactions, including zero, subject to the following rules:
j, the earliest day you may buy again is j + cooldown + 1.i and sell on day j, the holding duration is j - i days. You pay the fee costs[j - i] once for that transaction.The profit from buying on day i and selling on day j is prices[j] - prices[i] - costs[j - i].
Return the maximum total profit you can achieve. If no profitable transactions are possible, return 0.
Example 1:
Input: prices = [1,5,3], cooldown = 1, costs = [2,0,1]
Output: 4
Explanation:
The optimal strategy is:
prices[0] = 1.prices[1] = 5. The holding duration is 1 day, so the holding cost is costs[1] = 0.5 - 1 - 0 = 4.cooldown = 1 prevents buying any stock on day 2, so no further transactions are possible.Example 2:
Input: prices = [1,2,5], cooldown = 0, costs = [0,2,1]
Output: 3
Explanation:
The optimal strategy is:
prices[0] = 1.prices[2] = 5. The holding duration is 2 days, so the holding cost is costs[2] = 1.5 - 1 - 1 = 3.Example 3:
Input: prices = [4,1,7], cooldown = 2, costs = [3,0,1]
Output: 6
Explanation:
The optimal strategy is:
prices[1] = 1.prices[2] = 7. The holding duration is 1 day, so the holding cost is costs[1] = 0.7 - 1 - 0 = 6.Example 4:
Input: prices = [3,1,4], cooldown = 0, costs = [2,1,0]
Output: 2
Explanation:
The optimal strategy is:
prices[1] = 1.prices[2] = 4. The holding duration is 1 day, so the holding cost is costs[1] = 1.4 - 1 - 1 = 2.Constraints:
1 <= n == prices.length <= 15001 <= prices[i] <= 1050 <= cooldown <= n - 1costs.length == n0 <= costs[i] <= 105No sample inputs for this problem yet. The examples in the statement show the format.