rmq

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
const int mx = 3e3+10;
int node [mx][mx<<2];

void update(int f,int p, int ans, int L, int R, int rt){
if(L == R) {
node[f][rt] = max(node[f][rt],ans);
return ;
}
int m = (L + R) / 2;
if (p <= m)
update (f,p, ans, L, m, 2 * rt);
if (p > m)
update(f,p, ans, m + 1, R, 2*rt+1);

node[f][rt] = max( node[f][2 * rt] , node[f][2 * rt + 1]);
}
int sea(int f,int st, int en, int L, int R, int rt){
if(st <= L&& R <= en) return node[f][rt];
int ans = 0;
int m = (L + R) / 2;
if(st <= m ) ans = max(ans, sea(f,st, en, L, m, rt * 2));
if(m < en) ans = max(ans, sea(f,st, en, m+1, R, rt * 2+1));//m+1写成m
return ans;
}
int a[mx];
int main(){
int t;
freopen("F:\\qq文件\\1004\\1004\\9.in","r",stdin);
s1(t);
while(t--){
int n,m,k,te,st,en;
s3(n,m,k);
for(int i = 1; i <= n; i++) s1(a[i]);
memset(node,-1,sizeof(node));
node[0][0] = 0;
for(int i = 1 ; i <= n ; i++) //位置
for(int j = 1; j <= m; j++){ //选取个数
st = i - k; if(st < 0) st = 0;
en = i-1;
te = sea(j-1,st,en,0,n,1);
if(te == -1) continue;
update(j,i,te+a[i],0,n,1);
}
cout<<sea(m,1,n,0,n,1)<<endl;
}


}