显示代码纯文本
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <stack>
#include <vector>
#include <map>
#include <queue>
#include <ctime>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const int inf=1061109567;
const int maxn=1010;
const int maxm=1010;
const int mod=1000000007;
int f[maxn];
int g[maxn];
int main()
{
freopen("KPengshuangcang.in","r",stdin);
freopen("KPengshuangcang.out","w",stdout);
//clock_t st=clock();
int n,k,a;scanf("%d%d",&n,&k);
for(int i=1;i<=k;i++) f[i]=g[i]=-inf;
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
for(int j=min(i,k);j>=1;j--)
{
g[j]=max(f[j],g[j]);
f[j]=max(f[j],g[j-1])+a;
}
}
printf("%d\n",max(f[k],g[k]));
//clock_t ed=clock();
//printf("\nTime used : %.5lf Ms\n",double(ed-st)/CLOCKS_PER_SEC);
return 0;
}