CodeForces 467C George and Job

来源:互联网 发布:淘宝西班牙代购真假 编辑:程序博客网 时间:2024/05/29 15:24

*time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output*


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 sequence of n integers p1, p2, …, pn. You are to choose k pairs of integers:

[l1, 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 cope with the task.

Input
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, …, pn (0 ≤ pi ≤ 109).

Output
Print an integer in a single line — the maximum possible value of sum.

Examples

input

5 2 1
1 2 3 4 5

output

9

input

7 1 3
2 10 7 18 5 33 0

output

61

#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;#define INF 0x3f3f3f3f__int64 m,k,n,sum[10000],dp[5002][5002];void DP(){    int i,j;    for(i=m;i<=n;i++)    {        for(j=1;j<=k;j++)        {            dp[i][j]=max(dp[i-m][j-1]+sum[i]-sum[i-m],dp[i-1][j]);//取当前长度为m的块和不取中选择最大的,当不取当前块的时候就需要从i-1块中取得满足条件最大的j块(当从i-1块中取的时候就不能再取当前的那块了)        }    }    printf("%I64d\n",dp[n][k]);}int main(){    __int64 i,j,t,math[6000];    while(~scanf("%I64d%I64d%I64d",&n,&m,&k))    {        sum[0]=0;        for(i=1;i<=n;i++)        {   scanf("%I64d",&math[i]);        sum[i]=sum[i-1]+math[i];//将前i个数值的和保存在当前sum中        }        DP();    }    return 0;}
0 0
原创粉丝点击