F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Klee likes making friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/65536 K (Java/Others)
Total Submission(s): 2058    Accepted Submission(s): 599


Problem Description
Klee likes to make friends,now there are n people standing in a line and Klee can make friend with the $ i^{th} $ people with a cost of $ a_i $, 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.
 

Input
The first line of the input contains a single integer $ T (1 \le T \le 20) $indicating the number of test cases.

In each test case:

The first line contains two integers$ n, m. (2 \le n \le 20000, 2 \le m \le 2000, m \le n )$

The second line contains n intergers $ a_1, a_2, ... , a_n (0 \le a_i \le 20000) $

It's guarenteed that in all test cases, $ \sum n \le 50000 $
 

Output
For each test case:

You need to print a integers represents the smallest cost.
 

Sample Input
1 7 3 1 5 7 2 1 4 8
 

Sample Output
13
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 00:31:20, Gzip enabled