divk

Time limit: 0.2s Memory limit: 64MB Input: divk.in Output: divk.out

Task

For a sequence x1,x2,xmx_1, x_2, \dots x_m of integers, we define the following terms:

A subarray (i,j)(i, j) is the sequence formed by the numbers xi,xi+1,xi+2,xjx_i, x_{i+1}, x_{i+2}, \dots x_j in this order.

The sum of a subarray (i,j)(i, j) is the sum of the values in the sequence. More precisely, xi+xi+1+xi+2+xjx_i + x_{i+1} + x_{i+2} + \dots x_j.

A subarray is a kk-subarray if and only if the length of the subarray is divisible by kk.

Task

Given nn, kk, and a sequence a1,a2,ana_1, a_2, \dots a_n of integers, find the maximum sum of a kk-subarray.

Note! You are allowed to choose a subarray of length 00 (which has a sum of 00). Therefore, the answer is at least 00.

Input data

The first line of the input file divk.in contains two integers, nn and kk. The second line contains the sequence a1,a2,ana_1, a_2, \dots a_n of integers.

Output data

The first line of the output file divk.out will contain a single integer, the maximum sum of a kk-subarray.

Constraints and clarifications

  • 1kn10000001 \leq k \leq n \leq 1\,000\,000
  • 109ai109-10^9 \leq a_i \leq 10^9 for each ii from 11 to nn.
# Points Constraints
1 27 1n50001 \leq n \leq 5\,000
2 19 k=1k = 1
3 24 k=2k = 2
4 30 No additional constraints

Example 1

divk.in

5 3
9 -1 8 4 -13

divk.out

16

Explanation

We have k=3k = 3.

We can choose the 33-subarray (1,3)(1, 3) which has the sum 9+(1)+8=169 + (-1) + 8 = 16. We cannot choose the subarray (1,4)(1, 4) because its length is 44, and 44 is not divisible by 33.

Example 2

divk.in

5 1
9 -1 8 4 -13

divk.out

20

Explanation

k=1k = 1

We can choose the 11-subarray (1,4)(1, 4). It has the sum 9+(1)+8+4=209 + (-1) + 8 + 4 = 20.

Example 3

divk.in

7 3
-1 -1 -1 9 -1 -1 -1

divk.out

7

Explanation

k=3k = 3

There are multiple subarrays that obtain the sum 77. For example, we can choose the 33-subarray (3,5)(3, 5). It has the sum (1)+9+(1)=7(-1) + 9 + (-1) = 7.

Example 4

divk.in

3 2
-1 -1 -1

divk.out

0

Explanation

k=2k = 2

We observe that any subarray of length 1\geq 1 has a negative sum. Therefore, we can choose the empty subarray which has a sum of 00.

Log in or sign up to be able to send submissions!