day2
作者:
__492
,
2024-05-29 20:25:06
,
所有人可见
,
阅读 2
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6+9;
int n,m;
int a[N],q[N];
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] += a[i - 1];
}
deque<int>q;
q.push_back(0);
int ma=0;
for (int i = 1; i <= n; i++)
{
while (q.front() + m < i)
q.pop_front();
ma = max(ma, a[i] - a[q.front()]);
while (q.size() && a[q.back()] >= a[i])
q.pop_back();
q.push_back(i);
}
cout << ma;
return 0;
}