#C6802. Subarray Sum Calculation
Subarray Sum Calculation
Subarray Sum Calculation
Given an array of integers and two indices l and r (0-indexed), compute the sum of the subarray from index l to r (both inclusive).
The input consists of an integer n (number of elements), a dummy parameter x (unused, provided for possible future extensions), followed by n integers representing the array, then two integers l and r. The answer is the sum of elements from index l to r.
The mathematical formulation is given by:
\( S = \sum_{i=l}^{r} a_i \)
inputFormat
The first line contains two integers n
and x
.
The second line contains n
space-separated integers denoting the array elements.
The third line contains two integers l
and r
, the starting and ending indices of the subarray (0-indexed).
outputFormat
Output a single integer, the sum of the elements from index l
to r
of the array.
7 2
2 4 6 8 10 12 14
1 3
18
</p>