提交时间:2023-08-14 16:24:03

运行 ID: 98366

#include<bits/stdc++.h> using namespace std; #define ll long long #define N 200005 ll sum[N]; ll a[N]; deque<int>q; int main(){ int n,k; ll x; scanf("%d%d%lld",&n,&k,&x); if(x<0)x=-x,k=n-k; for(int i=1;i<=n;i++) scanf("%lld",&a[i]),a[i]-=x,sum[i]=sum[i-1]+a[i]; ll ans=0,minn=0; for(int i=1;i<=n;i++){ if(i>k){ minn=min(minn,sum[i-k]); ans=max(ans,sum[i]-minn+2*x*k); } if(!q.empty()&&i-q.front()+1>k)q.pop_front(); while(!q.empty()&&sum[q.back()]+2*q.back()*x>sum[i]+2*i*x)q.pop_back(); q.push_back(i); ans=max(ans,sum[i]+2*i*x-(sum[q.front()]+2*q.front()*x)); } printf("%lld",ans); return 0; }