#C11619. Circular Sum Computation
Circular Sum Computation
Circular Sum Computation
You are given a circular array of integers and an integer k. For each element in the array, compute the sum of the next k elements. The array is considered to be circular, meaning that after the last element, you wrap around to the beginning.
The operation for each index i can be expressed in LaTeX as follows:
$$s_i = \sum_{j=1}^{k} a_{(i+j) \bmod n}$$
where n is the length of the array and a
is the array.
If the array is empty, simply output an empty result.
inputFormat
The input is read from standard input (stdin
) and has the following format:
- The first line contains two integers,
n
andk
, wheren
is the number of elements in the array andk
is the number of elements to sum for each index. - If
n > 0
, the second line containsn
space-separated integers representing the array.
outputFormat
The output is written to standard output (stdout
) as a single line containing n
space-separated integers. Each integer is the sum of the next k
numbers in the circular array corresponding to each index.
5 2
1 2 3 4 5
5 7 9 6 3
</p>