#K701. Maximum Profit
Maximum Profit
Maximum Profit
You are given one or more datasets, each consisting of a list of stock prices in chronological order. Your task is to compute the maximum profit that could be achieved by buying a stock on one day and selling it on a later day. Formally, for each dataset, you need to find
\( \max_{i < j} (price[j] - price[i]) \),
and if no profit can be made, output 0.
inputFormat
Input is provided via standard input. Each line corresponds to a dataset containing space-separated integers that represent the stock prices in chronological order. If a line is empty, consider it as an empty dataset and output 0.
outputFormat
For each dataset (i.e., each input line), output a single integer denoting the maximum profit obtainable, with each result printed on its own line via standard output.## sample
7 1 5 3 6 4
5
</p>