Best Time to Buy and Sell Stock
Very easy
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.
You want to maximize your profit by selecting one day to buy one stock and choosing another day in the future to sell that stock.
Find the maximum profit that can be obtained from this transaction.
Input
The first line contains the size of the price array. The second line contains the array of prices — integers, each not exceeding .
Output
Print the maximum profit that can be obtained from one transaction. If it is impossible to obtain profit, print .
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 764
Acceptance rate 53%