I know it's right, my code is accepted. But how to prove this method is mathmetically right ?
How to prove the method "buy today sell tomorrow only if the price tomorrow is higher" is right mathmetically?

Consider first a contiguous subsequence of increasing prices.
The profitmaximizing strategy within this subsequence is to buy on the first day and sell on the last day
because this is the only strategy that realizes all of the daytoday gains within the subsequence.Notice further that the entire sequence can be decomposed into a series of
maximallysized contiguous subsequences of increasing prices, some of which might be trivial, i.e., of length 1.
It never makes sense to buy in one such subsequence A and then sell in a following subsequence B, since we could
always do better by inserting a sale at the end of A and a buy at the beginning of B.Therefore profit can be maximized by identifying each maximallysized contiguous subsequence of increasing prices,
and buying at the beginning of it and selling at the end of it.However, there is more to the story!
Because this strategy realizes all of the daytoday gains within each subsequence, and we have described how
the entire sequence can be decomposed into such subsequences, it follows that this strategy
realizes all of the daytoday gains within the entire sequence.
Since we are only asked to return the total profit and not the actual transaction log,
it suffices to sum together the daytoday gains across the entire sequence.