Trade Every Rise
Same prices, but you may buy and sell as often as you like (hold at most one share). Print the maximum total profit.
Input: the first line has N; the second line has N prices.
Output: the best cumulative profit.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ pi ≤ 109
Sample Tests
Input 1
6 7 1 5 3 6 4
Output 1
7
Input 2
3 5 5 5
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.