P14473 [HackerEarth] On a planet called Natoon, a person's wealth as well as health is measured by the amount of gold the person has. For example if a person has 2kg of gold then he will leave 2 more days [2
提高-
题目描述

On a planet called Natoon, a person's wealth as well as health is measured by the amount of gold the person has. For example if a person has 2kg of gold then he will leave 2 more days [2kg=2000gm=2days]. The gold can be borrowed/lend from/to other persons or gold banks. The person in need of your help is Mr. Jabba.

Mr. Jabba is running out of gold and hence his death is coming nearer. Mr. Jabba needs your help to live longer.

A very wealthily person decides to give away free gold worth 1000 years.

The person releases N slips, A[1],A[2],…..A[N]. Each slip has a gold-amount(can be both +ve and -ve).

A person can pick any number of slips(even none, or all of them, or some of them) out of the N slips.

But the rich person has a restriction, he announced one more number K. Restriction is that, if a person picks a slip A[i], then the next slip that he can choose to pick will me A[i+K+1]. It means there should be a difference of at least K between the indices of the slips picked.

Now slips should be picked in such a way that their sum results in maximum positive time-amount possible with given restriction.

If you predict the maximum positive sum possible, then you win.

Help our Jabba the Hutt in order to live longer!

Input:::
First line of the test file contains single number T, the number of test cases to follow.
Each test case consists of two lines.
First line contains two numbers N and K , separated by a space. Second line contains the N numbers A[1], A[2] ..... A[N] separated by space.

Output:::
For every test case, output in a single line the maximum positive sum possible, that is output for the case.

Constraints:
T ≤ 250,
N ≤ 10000,
-109 ≤ A[i] ≤ 109,
0 ≤ K ≤ N-1

SAMPLE INPUT
2
10 1
1 2 -3 -5 4 6 -3 2 -1 2
10 2
1 2 -3 -5 4 6 -3 2 -1 2

SAMPLE OUTPUT
12
10

Explanation

1st Case: We can take slips { A[2]=2, A[6]=6, A[8]=2, A[10]=2 }, slips are atleast 1 indices apart this makes maximum sum, A[2]+A[6]+A[8]+A[10]=12

2nd Case: We can take slips { A[2]=2, A[6]=6, A[10]=2 }, slips are atleast 2 indices apart this makes maximum sum, A[2]+A[6]+A[10]=10

输入格式

见题面

输出格式

见题面

样例输入
30 16 3 -334 -500 -169 -724 -478 -358 -962 -464 -705 -145 -281 -827 -961 -491 -995 -942 22 2 391 604 902 153 292 382 421 716 718 895 447 726 771 538 869 912 667 299 35 894 703 811 17 5 -673 141 -253 -547 662 -37 723 -529 316 190 288 40 -264 446 -890 370 6 18 2 -629 -84 756 966 -931 -944 -626 -537 118 929 833 -639 704 977 673 21 924 -270 22 19 97 986 161 355 -655 31 350 -941 966 107 7 457 -753 -945 -209 -221 422 506 -413 900 762 -410 19 0 -548 595 602 291 374 596 -348 -668 -281 -53 -418 -900 127 -728 -648 807 310 -813 309 20 0 -600 519 -798 -224 -844 989 195 -93 523 -314 448 -458 580 798 -589 9 472 538 -38 190 23 0 -815 156 -202 272 328 362 -875 869 844 -881 322 -21 557 -892 75 600 -3 -861 -401 -255 2 182 88 22 0 832 -169 -721 -976 368 425 -434 441 145 -718 -139 279 -687 549 -866 193 297 286 488 -455 114 316 21 0 313 -185 -912 832 313 -321 646 -481 196 129 535 173 -44 -292 -253 154 -745 -186 474 -168 787 23 1 202 -477 -314 -334 -372 833 487 518 773 -763 192 102 213 -802 527 -543 23 61 3 -505 725 492 222 19 1 187 -413 270 -235 711 896 285 -140 -695 19 -576 658 371 -678 -851 -18 119 800 60 15 1 170 576 -43 -164 882 565 -577 625 -629 423 902 123 737 195 264 17 1 30 11 411 153 -790 -188 940 -662 -900 -958 365 477 -58 303 -357 -477 113 16 1 -460 -993 405 -111 835 72 823 556 626 526 337 869 896 617 717 585 18 17 229 559 296 53 -584 654 -457 -532 -607 911 -67 -675 223 754 741 459 221 -626 20 19 -850 279 -193 -637 -556 176 -962 881 413 855 142 611 -424 -752 -296 -40 875 818 17 112 24 23 -40 685 -497 990 -353 651 -44 -335 192 264 -503 -775 292 549 561 467 129 -813 601 -215 213 824 -392 -670 22 21 75 498 287 -604 -221 -706 10 489 164 -619 -591 818 750 -975 303 98 -584 -971 913 545 -546 769 24 23 -289 865 -245 318 -601 132 152 -570 -901 423 -600 15 -28 -347 943 -409 49 588 608 -221 -954 146 -949 430 23 5 783 226 -38 -629 -748 359 -766 -955 726 25 -1 -496 -515 342 913 -196 72 -606 -429 705 812 93 36 16 10 256 -936 482 15 230 625 637 690 -662 -893 416 8 -233 -303 303 -148 22 5 28 -80 858 155 -264 -676 909 -561 948 -653 220 923 -369 -259 619 3 -781 392 -313 589 938 410 19 5 -959 -515 -937 58 -971 117 555 -330 -212 -82 85 -484 380 951 -115 -110 -73 977 -956 18 17 -790 -363 -184 200 -885 -71 -867 -295 825 629 -598 693 80 249 -528 864 405 816 21 2 -681 340 21 -721 309 -902 124 745 423 -806 318 907 481 136 -114 84 -290 996 54 -708 491 16 7 958 704 -52 -479 -423 -866 498 196 -633 22 392 925 458 -807 830 -600 24 0 882 315 762 336 418 828 816 449 -658 520 560 162 675 -361 398 714 -188 -638 75 521 -615 234 -905 557 16 5 469 923 333 910 336 -278 -636 164 949 505 4 -623 -970 568 85 373 19 0 396 249 -174 943 -941 419 805 216 -615 64 -893 509 -695 589 -172 358 268 510 -774
样例输出
0 4795 1169 3796 986 4011 5261 4657 4733 4552 3748 2930 3986 2274 4760 911 881 990 913 943 3234 785 3363 1532 864 3788 1883 9222 2245 5326