#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f3f3f3f
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define ll __int64
#define int ll
//typedef  long long ll;
typedef unsigned long long ull;
const int MAXN=1e6+10;
const int MOD=1e9+7;
const double eps=1e-6;
using namespace std;
//-------------------------------------------//
int a[MAXN],pre_max[MAXN],temp[MAXN];
signed main()
{
    int n,m;
    while(scanf("%lld%lld",&m,&n)!=EOF)
    {
        int ans=-INF;
        for(int i=0;i<=m;++i)pre_max[i]=-INF,temp[i]=-INF;
        for(int i=1; i<=n; ++i)scanf("%lld",&a[i]);//cout<<"?";
        for(int i=1; i<=n; ++i)
        {
            int temp1=0;
            for(int j=1; j<=min(m,i); ++j)//temp[j]=dp[i-1][j]
            {
                temp[j]=max(temp[j],temp1)+a[i];
                temp1=pre_max[j];
                pre_max[j]=max(pre_max[j],temp[j]);
            }
            ans=max(temp[m],ans);
            //cout<<dp[1][i]<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}
posted on 2019-11-16 20:43  megadeth  阅读(147)  评论(0编辑  收藏  举报