java算法盈利问题

public class HorsePrice {
    public static void main(String[] args) {
        int[] prices = {345, 336, 389, 270, 226, 350};
        trade(prices);
    }

    public static void trade(int[] prices) {
        //总天数
        int len = prices.length;
        //买入的价格索引(即天数-1)
        int buyIndex = 0;
        //卖出的价格索引(即天数-1)
        int sellIndex = 0;
        //利润
        int profit = 0;
        for (int i = 0; i < len; ++i) {
            for (int k = i; k < len; ++k) {
                int p = prices[k] - prices[i];
                if (p > profit) {
                    profit = p;
                    buyIndex = i;
                    sellIndex = k;
                }
            }
        }
        System.err.printf("第 %d 天买入,第 %d 天卖出,盈利 %d", ++buyIndex, ++sellIndex, profit);
    }
}
第 5 天买入,第 6 天卖出,盈利 124

 

每天都要卖出所有马匹么? 可以连续几天都买入马匹么? 一次必须卖完全部手中的马匹么?  能预先知道几天后的价钱么?