#K6886. Maximum Profit: Contiguous Stock Trading
Maximum Profit: Contiguous Stock Trading
Maximum Profit: Contiguous Stock Trading
You are given a list of stock price changes. Your task is to compute the maximum profit obtainable from a contiguous subarray of these price changes. In mathematical terms, given an array of integers \(a_1, a_2, \dots, a_n\), find the maximum value of:
[ \max_{1 \leq i \leq j \leq n} \sum_{k=i}^{j} a_k ]
This problem can be efficiently solved using Kadane's algorithm.
inputFormat
The input is read from stdin
and consists of two lines:
- The first line contains a single integer \(n\), the number of stock price changes.
- The second line contains \(n\) space-separated integers representing the stock price changes.
outputFormat
Output a single integer to stdout
— the maximum profit obtainable from any contiguous subarray of the given list of stock price changes.
6
-10 1 3 -2 4 -1
6
</p>