题意:不能取连续的K个奶牛
#include <cstring>
#include <iostream>
#include <algorithm>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m;
LL s[N],f[N];
int q[N];
LL g(int i)
{
if (!i) return 0;
return f[i - 1] - s[i];
}
int main()
{
cin>>n>>m;
for (int i = 1; i <= n; i ++ ) cin>>s[i],s[i]+=s[i-1];
int hh = 0, tt = 0;
for (int i = 1; i <= n; i ++ )
{
if(q[hh]+m<i) hh++;
f[i]=max(f[i-1],s[i]+g(q[hh]));
while(hh<=tt&&g(i)>=g(q[tt])) tt--;
q[++tt]=i;
}
cout<<f[n];
}