Troop selection

4.1

18 votes
Problem

The war is going on between star world and dark world. The king of the starworld need to choose troops of soldiers and send them for war. There are two type of soldiers 1 and 0. He can choose atmost k troops and in each troop he can choose consecutive s soldiers from the soldiers who are standing in a row.

Now the problem is soldier of 1 type is more powerful than 0. so he wanted to maximize no. of soldiers having type 1.

Help him to find maximum number of soldiers having type 1.

Input :
first line contains T- no. of test cases.
In each test case first line contains three space separated integers n , k ans s - no. of soldiers , no. of troops , consecutive soldiers in each troop.
Third line contains n space separated integers indicating type of soldier 0 or 1.

Output :
Print maximum number of soldiers of 1 type he is able to choose.

Constraints :
1≤ T ,s ,n, k ≤103
1≤ sum of n/s over all test cases ≤104

Sample Input
5
5 2 2
1 1 1 1 1
6 2 2
1 0 1 0 1 1
6 2 2
1 0 0 0 1 1
7 1 4
1 0 0 0 1 1 1
7 2 4
1 0 0 0 1 1 1
Sample Output
4
3
3
3
3
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?