#K71707. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
Given the daily stock prices, your task is to determine the maximum profit achievable. The profit calculation allows for multiple transactions, where you buy on one day and sell on a later day. The rule is simple: if the price of the stock increases from one day to the next, you can profit from that increase.
Formally, if the stock prices are given by \(A = [a_1, a_2, \dots, a_n]\), the maximum profit is computed as \[ \sum_{i=1}^{n-1} \max(0, a_{i+1} - a_i)\]
Note that if there is no opportunity for profit, you should return 0.
inputFormat
The input is read from standard input (stdin). The first line contains an integer \(n\) denoting the number of days. The second line contains \(n\) space-separated integers, each representing the stock price on that day.
outputFormat
Output the maximum profit as a single integer to standard output (stdout).
## sample6
7 1 5 3 6 4
7