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
Given a row of valued pins, pick up to k non-overlapping blocks of exactly w consecutive pins to maximize the total score.
Level

Medium6 of 10

Topics
Dynamic programming, Prefix sum
Solved
No attempts yet

Problem

At a carnival, a popular game is Bowling for Numbers. A large number of bowling pins are lined up in a row. Each pin has a number printed on it, which is the score you earn for knocking that pin over. You are given several bowling balls; each ball is wide enough to knock over a few consecutive, adjacent pins.

For example, suppose the row of pins is:

2 8 5 1 9 6 9 3 2

If you are given two balls, each able to knock over three adjacent pins, the best score you can achieve is 3939: one throw knocks over 2+8+5=152 + 8 + 5 = 15 and the other knocks over 9+6+9=249 + 6 + 9 = 24. No two throws may overlap, because a pin that has already been knocked over cannot be knocked over again.

A greedy approach — repeatedly taking the throw worth the most among the pins still standing — often comes close, but it does not always reach the maximum. Your task is to compute the true maximum score.

Each ball knocks over a block of exactly ww consecutive pins from the original row, and no two balls may cover the same pin. You do not have to use every ball.

Input

The input consists of several test cases.

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

Each test case begins with a line containing three integers nn, kk, and ww:

  • nn (1≤n≤300001 \le n \le 30000) — the number of bowling pins;
  • kk (1≤k≤5001 \le k \le 500) — the number of balls available;
  • ww (1≤w≤n1 \le w \le n) — the width of each ball, i.e. the number of adjacent pins it knocks over.

The next nn lines each contain a single non-negative integer less than 1000010000, giving the score of each pin, in order.

Output

For each test case, output a single line containing the maximum score the player can achieve. This score is guaranteed to be less than one billion.

Examples2

  1. Example 1

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

    Input
    3
    9 2 3
    2
    8
    5
    1
    9
    6
    9
    3
    2
    5 3 5
    1
    2
    3
    4
    5
    5 2 1
    3
    1
    4
    1
    5
    
    Expected output
    39
    15
    9