求一个子段和最大,且子段长度不小于m
作者:
超级无敌厉害
,
2024-02-29 17:27:06
,
所有人可见
,
阅读 42
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define int long long
typedef pair<int, int> PII;
const int N = 1e5 + 10;
int t, n, m;
int a[N], s[N];
map<int, int> mp1;
signed main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
s[i] = s[i - 1] + a[i];
}
int minv = 1e9;
int ans = -1e9;
for (int i = m; i <= n; i++)
{
minv = min(minv, s[i - m]);
ans = max(ans, s[i] - minv);
}
cout << ans << endl;
return 0;
}