classSolution { public: intmaxProfit(vector<int>& prices, int fee){ int res = 0, min = prices[0]; for(int i = 0; i < prices.size(); ++i) { if(prices[i] < min) min = prices[i]; if(prices[i] > min + fee) { res += prices[i] - min - fee; min = prices[i] - fee; } } return res; } };