Beat that Sharingan

0

0 votes
Problem

You are the leader of your army the ANBU cops.You are on a man hunt with your army. Your target is a rogue ninja who fled the Konhana village possesing Mangekyō Sharingan which can put anyone under genjutsu (hypnosis). You have to select an army out of N available ninjas whose power-levels are given in the form of an array with N integers. The issue is that your target already has you under his hypnosis which makes you believe that you cannot pick more than X consecutive ninjas from the array. Whilst under this hypnosis, maximise the sum of power-levels of the ninjas you are recruiting and provide it as the answer,

Input format

First line of input contains N and X.

Second line of input contains N integers A1, A2, A3...., An. These represent the power levels of the N ninjas.

Output format

Print the answer for each test case in a new line. The answer for each test case is equal to the maximum sum of power-levels you can obtain such that more than X ninjas in a row are not selected from the array.

Constraints

  • 1 <= X, N <= 2000
  • 1 <= Ai <= 1e9 for every i from 1 to N
  • Sum of X and sum of N across all test cases does not 2000

 

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?