Forests of Fangorn

Time limit: 2 secMemory limit: 256 MBData Structures, Math, Dynamic Programming

Problem Statement

In the ancient forests of Fangorn, legends speak of a series of mystic stones imbued with magical energy. A brave wanderer has set out on a journey to collect these energies to unlock a long-forgotten power. The stones are arranged in a straight line and numbered from 11 to NN. Each stone ii holds a magic value AiA_i.

The wanderer starts on the first stone (stone 11) and must reach the last stone (stone NN). However, the magic within each stone is delicate; the wanderer can only jump from stone ii to stone jj if the condition
i<ji+Ki < j \leq i + K
is met. On landing at a stone, the wanderer collects its magic value. His task is to maximize the total magic points he can gather by the time he reaches stone NN.

Your task is to compute the maximum magic points that can be accumulated on a valid journey from stone 11 to stone NN.

Input Format

  • The first line contains two integers, NN and KK, where
    • NN is the number of mystic stones, and
    • KK is the maximum allowed jump length.
  • The second line contains NN space-separated integers, A1,A2,,ANA_1, A_2, \dots, A_N, where AiA_i is the magic value of stone ii.

Output Format

Print a single integer denoting the maximum total magic points the wanderer can collect while reaching the last stone.

Examples

Input

5 2
1 2 3 4 5

Output

15

Input

3 1
10 -5 20

Output

25

Code Editor

Submit a solution. Authentication is required to create submissions.

Language
Theme
Source code is submitted to the judge for testing.