import java.util.*;


public class Solution {
    /**
     * 
     * @param prices int整型一维数组 
     * @return int整型
     */
    public int maxProfit (int[] prices) {
        int res = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            int length = 1;
            while ((i + length) < prices.length && prices[i + length] > prices[i + length - 1]) {
                length++;
            }
            length--;
            res += prices[i + length] - prices[i];
            i += length;
        }
        return res;
    }
}