Stock Maximize
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Your algorithms have become so good at predicting the market that now you know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next number of days.
Each day, you can either buy one share of WOT, sell any number of shares of WOT that you own, or not make any transaction at all. What is the maximum profit you can obtain with the optimum trading strategy?
Input
The first line contains the number of predicted prices for WOT. The next line contains integers , each is a predicted stock price on the -th day.
Output
Print the maximum profit that can be obtained in the market.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 199
Acceptance rate 49%