求助!40pts求调
  • 板块灌水区
  • 楼主Quartz_Blocks
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/5 10:06
  • 上次更新2024/5/5 11:36:32
查看原帖
求助!40pts求调
1059176
Quartz_Blocks楼主2024/5/5 10:06

题目传送门 提交记录传送门

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
long long a[10000010],n,m;
long long b[10000010];
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
		b[i] = a[i]+b[i-1];
	}
	long long mx = -1e16;
	for(int i = m;i <= n;i++){
		long long res = b[i]-b[i-m];
		int j = i;
		while(a[j] < 0 && j >= i){
			res -= a[j];
			j--;
		}
		mx = max(res,mx);
	}
	cout << mx;
	return 0;
}
2024/5/5 10:06
加载中...