include bits stdc using namespace std define MAXN 30100 define INF 1e9

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define MAXN 30100
#define INF 1e9
#define WL(t) while(t--)
#define FOR(i,s,e) for(int i=s; i<=e; i++)
int p[MAXN], prefix[MAXN];
int n, k, w;
int max_val;
class fastio {
public:
fastio() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
}
} __fastio;
void prefixSum() {
prefix[0] = 0;
FOR(i,1,n) {
prefix[i] = prefix[i-1] + p[i];
}
}
void input() {
cin >> n >> k >> w;
p[0] = 0;
FOR(i,1,n) {
cin >> p[i];
}
}
int f(int i, int k, int r) {
if(k == 0) return 0;
if(i > n) return 0;
if(i - w < r) return f(i+1, k, r);
max_val = -INF;
for(int j=1; j<=n; j++) {
max_val = max(max_val, f(i+j, k-1, i) + prefix[i] - prefix[i-w]);
}
return max_val;
}
void solve() {
input();
prefixSum();
int maxi = -INF;
FOR(i,1,n) {
maxi = max(maxi, f(i,k,0));
}
cout << maxi << endl;
}
int main() {
__fastio;
int t; cin >> t;
WL(t) {
solve();
}
return 0;
}