I have the same idea with you.

But I transform the prices array as price differences, so that it becomes similar to the problem 53 Maximum Subarray.

Here is my code.

int Solution::maxProfit_split(vector<int>& prices) {
int n = prices.size();
if (n < 2) {
return 0;
}
int current_profit;
current_profit = 0;
vector<int> max_profit_left(n);
max_profit_left.front() = 0;
for (int i = 1; i < n; ++i) { // max profit on interval [0, i]
current_profit = max(current_profit, 0);
current_profit += prices[i] - prices[i - 1];
max_profit_left[i] = max(max_profit_left[i - 1], current_profit);
}
current_profit = 0;
vector<int> max_profit_right(n);
max_profit_right.back() = 0;
for (int i = n - 2; i >= 0; --i) { // max profit on interval [i, n - 1]
current_profit = max(current_profit, 0);
current_profit += prices[i + 1] - prices[i];
max_profit_right[i] = max(max_profit_right[i + 1], current_profit);
}
int max_profit = 0;
for (int i = 2; i <= n - 2; ++i) { // two transactions
max_profit = max(max_profit, max_profit_left[i - 1] + max_profit_right[i]);
}
max_profit = max(max_profit, max_profit_left[n - 1]); // only one transaction
return max_profit;
}