← 返回 apple 的题目列表Maximum Profit from Stock Trading with at Most K Transactions
类型:online_judge
apple
Given an integer array where elements represent the price of a stock on the i-th day, and a non-negative integer k that represents the maximum number of transactions allowed. You can engage in multiple buy and sell transactions, but you can hold only one share of stock at a time. Write an algorithm to find the maximum profit. Transactions and transaction costs are not included in profit considerations. Provide adequate test cases and data range specifications.
Example:
Input:
k = 2, prices = [3,2,6,5,0,3]
Output:
7
Data range:
1 ≤ k ≤ 100, 0 ≤ prices[i] ≤ 1000, 0 ≤ prices.length ≤ 1000
Example
Input
2
3 2 6 5 0 3