Task
For a sequence of integers, we define the following terms:
A subarray is the sequence formed by the numbers in this order.
The sum of a subarray is the sum of the values in the sequence. More precisely, .
A subarray is a -subarray if and only if the length of the subarray is divisible by .
Task
Given , , and a sequence of integers, find the maximum sum of a -subarray.
Note! You are allowed to choose a subarray of length (which has a sum of ). Therefore, the answer is at least .
Input data
The first line of the input file divk.in
contains two integers, and . The second line contains the sequence of integers.
Output data
The first line of the output file divk.out
will contain a single integer, the maximum sum of a -subarray.
Constraints and clarifications
- for each from to .
# | Points | Constraints |
---|---|---|
1 | 27 | |
2 | 19 | |
3 | 24 | |
4 | 30 | No additional constraints |
Example 1
divk.in
5 3
9 -1 8 4 -13
divk.out
16
Explanation
We have .
We can choose the -subarray which has the sum . We cannot choose the subarray because its length is , and is not divisible by .
Example 2
divk.in
5 1
9 -1 8 4 -13
divk.out
20
Explanation
We can choose the -subarray . It has the sum .
Example 3
divk.in
7 3
-1 -1 -1 9 -1 -1 -1
divk.out
7
Explanation
There are multiple subarrays that obtain the sum . For example, we can choose the -subarray . It has the sum .
Example 4
divk.in
3 2
-1 -1 -1
divk.out
0
Explanation
We observe that any subarray of length has a negative sum. Therefore, we can choose the empty subarray which has a sum of .