#K36587. Maximum Subarray Sum Query
Maximum Subarray Sum Query
Maximum Subarray Sum Query
You are given an array of integers and two indices, start and end. Your task is to compute the maximum subarray sum for the subarray of the array defined by the indices start and end (inclusive).
In other words, if the given array is (a_0, a_1, \dots, a_{n-1}) and the subarray of interest is (a_{start}, a_{start+1}, \dots, a_{end}), you need to determine the maximum sum of any contiguous segment within this subarray. This can be represented by the formula:
[
\max_{start \leq i \leq j \leq end} \left( \sum_{k=i}^{j} a_k \right)
]
It is guaranteed that the indices provided are within the bounds of the array (0-indexed).
inputFormat
The input is given via stdin and consists of three lines:
- The first line contains a single integer (n) which denotes the number of elements in the array.
- The second line contains (n) space-separated integers representing the array elements.
- The third line contains two space-separated integers, (start) and (end), representing the starting and ending indices (0-indexed) of the subarray to consider.
outputFormat
Output a single integer which is the maximum subarray sum of the subarray defined by indices (start) to (end). The answer should be printed to stdout.## sample
9
-2 1 -3 4 -1 2 1 -5 4
0 3
4