-
Notifications
You must be signed in to change notification settings - Fork 5
/
467C.cpp
57 lines (51 loc) · 1.14 KB
/
467C.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//21171_somesh || asomesh999
//AC
#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;
int n, m, k;
vl arr, pref;
ll dp[5010][5010];
ll func(int pos, int count) {
if(pos >= n || count == k) {
return 0;
}
if((k - count) * m > (n - pos)) {
return INT_MIN;
}
if(dp[pos][count] != -1) {
return dp[pos][count];
}
return dp[pos][count] = max(func(pos + 1, count),
func(pos + m, count + 1) + pref[pos + m - 1] - ((pos - 1 >= 0) ? pref[pos - 1] : 0));
}
int main()
{
io
#ifdef SOMU
clock_t startTime = clock();
freopen("input.txt","r",stdin);
#endif
memset(dp, -1, sizeof dp);
cin >> n >> m >> k;
arr.resize(n);
pref.resize(n);
ll sum = 0;
fr(i, 0, n) {
cin >> arr[i], sum += arr[i];
pref[i] = sum;
}
cout << func(0, 0);
#ifdef SOMU
cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
#endif
return 0;
}