Codeforces round #267 (Div. 2) C. George and job

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.