#C9954. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
You are given the daily stock prices of a company. Your task is to determine the maximum profit that can be achieved by performing exactly one buy and one sell operation. If no profit can be made, output No profit
.
Note that the list of prices must contain between \(5\) and \(10\) integers, and each price is guaranteed to be between \(0\) and \(999999\). The profit is computed as the difference between the selling price and the minimum price seen before selling.
Example:
Input: 7 1 5 3 6 4 0 Output: 5
inputFormat
The input consists of multiple lines. Each non-terminating line contains a list of space-separated integers representing the stock prices for one dataset, followed by a trailing 0
which serves as a delimiter and should not be processed.
The input is terminated by a line that contains only a single 0
.
outputFormat
For each dataset, output the maximum profit on a separate line. If no profit is possible, output No profit
.
7 1 5 3 6 4 0
0
5
</p>