#P197. [Sleeping Cup #7] Rice Cake Consumption

[Sleeping Cup #7] Rice Cake Consumption

Person in Charge

Attention

The sample cases for this problem are not placed in subtask 0. Instead, they are located elsewhere:

Sample Data File Subtask ID Test Point
Sample 1 11.in / 11.out Subtask 2 #2-1
19.in / 19.out Subtask 3 #3-1
Sample 2 12.in / 12.out Subtask 2 #2-2

Sample 1 will be judged twice.

The subtask dependencies are as follows:

Subtask ID Depends on
Subtask 1 none
Subtask 2 Subtask 1
Subtask 3 none
Subtask 4 Subtasks 2 and 3

File I/O is required (ricecake.in / ricecake.out).

Problem Background

One evening, Sleeping Goose bought a skewer of rice cakes coated with chili sauce.

Problem Description

The bamboo skewer has nn positions for rice cakes, some of which are occupied (immovable) and some of which are empty.

Sleeping Goose wants to eat every rice cake in some order while minimizing the amount of chili sauce rubbed off.
When it decides to eat a rice cake, its beak touches all other rice cakes within at most kk positions of the chosen one.
Each time a rice cake is touched, 11 unit of sauce is removed.

Compute the minimum total units of sauce that will be rubbed off under the best possible eating order.

Input Format

Multiple test cases.
First line: an integer TT, the number of test cases.
For each test case:

  • First line: two integers n,kn, k.
  • Second line: a 01-string SS of length nn, where 1 indicates a rice cake at that position and 0 indicates no cake.

Output Format

For each test case, output one integer: the minimum total units of sauce rubbed off.

Samples

2
1 0
1
7 6
0000000
0
0
2
9 1
111010111
32 12
00110000100000000001000000110110
4
14

Sample 2 Explanation

For the first test case, an optimal eating order is:

  1. Eat the cake at position 5.
  2. Eat the cake at position 3; this touches the cake at position 2.
  3. Eat the cake at position 2; this touches the cake at position 1.
  4. Eat the cake at position 1.
  5. Eat the cake at position 8; this touches cakes at positions 7 and 9.
  6. Eat the cake at position 9.
  7. Eat the cake at position 7.

Data Range

For 100%100\% of the data: 1T1001 \le T \le 100, 1n1051 \le n \le 10^5, 0kn10 \le k \le n − 1.

There are four equally-weighted subtasks:

  1. n6n \le 6.
  2. n100n \le 100.
  3. Guaranteed k=n1k = n − 1.
  4. No additional constraints.