Best Time to Buy and Sell Stock 2
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
You are given an array of prices, where contains the price of a stock on the -th day.
Each day, you can decide whether to buy and/or sell stocks. At any given time, you can own at most one stock.
Find the maximum profit that can be obtained.
Input
The first line contains the size of the price array. The second line contains the price array - integers, each not exceeding .
Output
Print the maximum profit that can be obtained. If it is impossible to obtain a profit, output .
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 232
Acceptance rate 59%