记录编号 575442 评测结果 AAAAAAAAAA
题目名称 白色谎言 最终得分 100
用户昵称 Gravatarnick 是否通过 通过
代码语言 C++ 运行时间 0.897 s
提交时间 2022-09-14 21:51:37 内存使用 11.45 MiB
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define re register

const int INF = 0x3f3f3f3f;
using namespace std;

int n, m;
ll a[1000005], dp[2][1000005];

int main(){
	freopen("white_lies.in", "r", stdin);
	freopen("white_lies.out", "w", stdout);
	while(cin >> m >> n){ 
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int i = 0; i <= n; i++){
			dp[0][i] = 0;
			dp[1][i] = 0;
		}
		for (int i = 1, k = 1; i <= m; i++, k ^= 1){
            dp[k][i - 1] = -INF;
            ll maxl = -INF;
            for (int j = i; j <= n - m + i; j++){
                maxl = max(maxl, dp[k ^ 1][j - 1]);
                dp[k][j] = max(maxl, dp[k][j - 1]) + a[j];
            }
        }
		ll ans = -INF;
		for (int i = m; i <= n; i++){
			ans = max(ans, dp[m&1][i]);
		}
		printf("%lld\n", ans);
	}
	return 0;
}