题目传送门
提交记录传送门
#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;
}