-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathccc07s5.cpp
42 lines (38 loc) · 937 Bytes
/
ccc07s5.cpp
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
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> score;
int t, n, k, w;
int next(vector<int> &poi, vector<int> &sum)
{
for (int x = 1; x <= k; x++)
{
for (int y = n-1; y >= 0; y--)
{
if (y > n-w)
score[x][y] = sum[y];
else
score[x][y] = max(score[x-1][y+w]+sum[y], score[x][y+1]);
}
}
int ma = 0;
for (int x = 0; x < n; x++)
ma = max(ma, score[k][x]);
return ma;
}
int main()
{
scanf("%i", &t);
while (t--)
{
scanf("%i%i%i", &n, &k, &w);
vector<int> poi (n), sum (n,0);
score.resize(k+1, vector<int>(30001, 0));
for (int x = 0; x < n; x++)
scanf("%i", &poi[x]);
for (int x = 0; x < n; x++)
for (int y = 0; y < min(n-x,w); y++)
sum[x] += poi[x+y];
printf("%i\n", next(poi, sum));
}
return 0;
}