This page is still under construction.

Parts of this page are still being built. What you see may change.

Bowling for Numbers++

Time limit1sMemory limit128 MB

Summary
Choose at most k windows of length w, possibly overlapping beyond the row ends, so the sum of the covered pins is as large as possible.
Level

Medium7 of 10

Topics
Dynamic programming, Prefix sum, Array, Greedy
Solved
No attempts yet

Problem

You are playing a game called Bowling for Numbers. A row of nn bowling pins stands in a line. The ii-th pin has an integer score aia_i printed on it — the points you gain by knocking that pin over. Some pins are penalty pins whose score is negative, so knocking one over lowers your total.

You are given kk bowling balls. Each ball is wide enough to knock over up to ww consecutive pins: a single throw covers a window of ww adjacent positions and knocks over every pin still standing inside that window. A pin's score is counted at most once, no matter how many balls pass over it.

A throw's window may extend past the left or right end of the row (everything beyond the ends is empty space), and it may pass through gaps left by pins that earlier throws already knocked down. You can exploit this: by aiming a throw so that some of its ww positions land on empty space — off an end of the row, or on positions a previous throw already cleared — you can knock over fewer than ww pins and skip over penalty pins. A ball may even be thrown so that it knocks over nothing.

Throw your kk balls to maximize the total score of the knocked-over pins. You do not have to use every ball.

Equivalently: the pins you knock over are exactly those whose position is covered by at least one of your (at most kk) length-ww windows, and your score is the sum of aia_i over every covered position. Report the maximum score you can achieve.

Input

The first line contains an integer tt (1≤t≤101 \le t \le 10) — the number of test cases. The test cases follow.

The first line of each test case contains three integers nn, kk, and ww:

  • nn (1≤n≤100001 \le n \le 10000) — the number of pins;
  • kk (1≤k≤5001 \le k \le 500) — the number of balls;
  • ww (1≤w≤1001 \le w \le 100) — the width of a ball, i.e. how many consecutive pins one throw can knock over.

Each of the next nn lines contains one integer — the scores of the pins from left to right. Every score satisfies −10000≤ai≤10000-10000 \le a_i \le 10000.

Output

For each test case, print a single line containing the maximum total score that can be achieved. The answer is guaranteed to be less than one billion.

Examples2

  1. Example 1

    Input
    2
    9 2 3
    2
    8
    5
    1
    9
    6
    9
    3
    2
    9 3 3
    2
    8
    -5
    3
    5
    8
    4
    8
    -6
    
    Expected output
    39
    38
    
  2. Example 2

    Input
    1
    5 2 2
    -3
    5
    -3
    5
    -3
    
    Expected output
    7