https://www.luogu.org/problemnew/show/P1725

 

关于滑动窗口的解释https://www.cnblogs.com/albert67/p/10449039.html

dp[i]=max(dp[i-k])l<=k<=r+a[i]

#include<iostream>
#include<deque>
#include<algorithm> 
using namespace std;
int a[200005],dp[200005];
struct Node{
    int v,num;
};
deque<Node> q;
int main(){
    int n,l,r;
    cin>>n>>l>>r;
    for(int i=0;i<=n;i++)
        cin>>a[i];
    int p=0;
    struct Node tmp;
    for(int i=l;i<=n;i++){
        while(!q.empty()&&q.back().v<dp[p])
            q.pop_back();
        tmp.num=p;tmp.v=dp[p];
        q.push_back(tmp);
        while(!q.empty()&&q.front().num+(r-l+1)<=p)
            q.pop_front();
        dp[i]=q.front().v+a[i];
        p++;
    }
    cout<<*max_element(dp+n-r+1,dp+n)<<endl;
    return 0;
}