The new itone 6 has been released recently and George got really keen to buy it. unfortunately, he didn't have enough money, so George was going to work as a programmer. now he faced the following problem at the work.
Given a sequenceNIntegersP1 ,?P2 ,?...,?PN. You are to chooseKPairs of integers:
[
L
1 ,?R1],? [L2 ,?R2],?...,? [LK,?RK] (1? ≤?L1? ≤?R1? <?L2? ≤?R2? <?...? <?LK? ≤?RK? ≤?N;RI? -?LI? +? 1? =?M),?
In such a way that the value of sum is maximal possible. Help George to interact with the task.
Input
The first line contains three IntegersN,MAndK(1? ≤? (M? ×?K)? ≤?N? ≤? (5000). The second line containsNIntegersP1 ,?P2 ,?...,?PN(0? ≤?PI? ≤? 109 ).
Output
Print an integer in a single line-the maximum possible value of sum.
Sample test (s) Input
5 2 11 2 3 4 5
Output
9
Input
7 1 32 10 7 18 5 33 0
Output
61. The idea of dividing a sequence with a length of N into sub-sequences with a K segment length of m to calculate the sum of the K sub-sequences is as follows: DP [I] [J] indicates the maximum value of the J segment selected by the number of I. Obviously, this number is not selected, and this number is considered. Considering this number, the continuity will only increase to the M sequence ending with this number.#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef long long ll;using namespace std;const int maxn = 5100;ll num[maxn], sum[maxn], dp[maxn][maxn];ll n, m, k;int main() {cin >> n >> m >> k;for (int i = 1; i <= n; i++) {cin >> num[i];sum[i] = sum[i-1] + num[i];}for (int i = m; i <= n; i++)for (int j = k; j >= 1; j--)dp[i][j] = max(dp[i-1][j], dp[i-m][j-1]+sum[i]-sum[i-m]);cout << dp[n][k] << endl;return 0;}
Codeforces round #267 (Div. 2) C. George and job