## CCC '07 S5 - Bowling for Numbers

View as PDF

Points: 10 (partial)
Time limit: 5.0s
Memory limit: 256M

Problem type

At the Canadian Carnival Competition (CCC), a popular game is Bowling for Numbers. A large number of bowling pins are lined up in a row. Each bowling pin has a number printed on it, which is the score obtained from knocking over that pin. The player is given a number of bowling balls; each bowling ball is wide enough to knock over a few consecutive and adjacent pins.

For example, one possible sequence of pins is: 2 8 5 1 9 6 9 3 2

If the Alice was given two balls, each able to knock over three adjacent pins, the maximum score Alice could achieve would be , the sum of two throws: , and .

Bob has a strategy where he picks the shot that gives him the most score, then repeatedly picks the shot that gives him the most score from the remaining pins. This strategy doesn't always yield the maximum score, but it is close. On the test data, such a strategy would get a score of 20%.

#### Input Specification

Input consists of a series of test cases. The first line of input is , , indicating the number of test cases in the file. The first line of each test case contains three integers n k w. First is the integer , , indicating the number of bowling pins. The second integer, , , giving the number of bowling balls available to each player. The third and final integer is , , the width of the bowling ball (the number of adjacent pins it can knock over). The next lines of each test case each contain a single non-negative integer less than , giving the score of the pins, in order. 20% of the test data will have size .

#### Output Specification

For each test case, output the maximum achievable score by the player. This score is guaranteed to be less than one billion.

#### Sample Input

1
9 2 3
2
8
5
1
9
6
9
3
2

#### Output for Sample Input

39

• corgi  commented on Nov. 13, 2019, 12:37 p.m. edited

Could anyone check why I am getting RTE on the last case? EDIT: nvm

• defectivezuckerbot69  commented on Nov. 4, 2018, 12:02 p.m.

if, say, the sequence of pins is 1 2 3 4 5 6 7 8 9, and the width of the ball is 3, if I were to knock down 5 6 7, would I be able to then knock down 4 8 9, or would the space restrict me from doing so?

• Relativity  commented on Nov. 5, 2018, 9:34 a.m.

The space would restrict you from doing so.

• minecraftyugi  commented on Oct. 11, 2016, 11:16 p.m.

Is the input supposed to have a blank line after each line of numbers? For example, it is formatted like this instead of the example:

1

9 2 3

2

8

5

1

9

6

9

3

2
• Kirito  commented on Nov. 3, 2016, 6:50 p.m.

Fixed.