问题 J: Klee likes making friends

内存限制:64 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:12 通过:6

题目描述

Klee likes to make friends,now there are n people standing in a line and Klee can make friend with the ��ℎith people with a cost of ��ai, Klee has a principle that at least 2 out of m consecutive people must be her friends.Please help her calculate the minimum amount of costs she needs.

输入格式

The first line of the input contains a single integer �(1≤�≤20)T(1T20)indicating the number of test cases.

In each test case:

The first line contains two integers�,�.(2≤�≤20000,2≤�≤2000,�≤�)n,m.(2n20000,2m2000,mn)

The second line contains n intergers �1,�2,...,��(0≤��≤20000)a1,a2,...,an(0ai20000)

It's guarenteed that in all test cases, ∑�≤50000n50000

输出格式

For each test case:

You need to print a integers represents the smallest cost.

输入样例 复制

1
7 3
1 5 7 2 1 4 8

输出样例 复制

13

分类标签