Codeforces Round #267 (Div. 2) C. George and Job,

Source: Internet
Author: User

Codeforces Round #267 (Div. 2) C. George and Job,

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, bytes,P2, middle..., middle ,...,PN. You are to chooseKPairs of integers:

[ L 1, bytes,R1], region [L2, bytes,R2], numbers..., numbers [LK, Bytes,RK] (1 limit ≤ limitL1 bytes ≤ bytesR1 worker <workerL2 bytes ≤ bytesR2 rows <values... rows <valuesLKLimit ≤ limitRKLimit ≤ limitN;RIAccept-Encoding-LIBytes + bytes 1 records = bytesM), Then ),

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 limit ≤ limit (MLimit × limitK) Bytes ≤ bytesNLimit ≤00005000). The second line containsNIntegersP1, bytes,P2, middle..., middle ,...,PN(0 bytes ≤ bytesPILimit ≤ limit 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;}





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.