#include <iostream>
#include <vector>
using namespace std;
int maxProfit(vector<int> &prices) {
size_t size = prices.size();
if (size <= 1) {
return 0;
}
int profit = 0;
int buy = 0;
int sell = 0;
while(++sell < size) {
if (prices[sell] < prices[sell-1]) {
profit += prices[sell-1]-prices[buy];
buy = sell;
}
}
profit += prices[sell-1]-prices[buy];
return profit;
}