提交时间:2023-08-14 12:00:27

运行 ID: 98092

#include<cstdio> typedef long long ll; inline ll read(){ ll x=0; int f=0,ch=0; while(ch<48||ch>57) f=(ch=='-'),ch=getchar(); while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar(); return f?-x:x; } inline void write(ll x,char end='\n'){ if(x==0){ putchar('0'); putchar(end); return; } if(x<0) putchar('-'),x=-x; int ch[70]={0},cnt=0; while(x){ ch[cnt++]=(int)(x%10); x/=10; } while(cnt--) putchar(ch[cnt]+48); putchar(end); } inline ll max(ll x,ll y){return x>y?x:y;} const int N=2e5+5; ll n,k,x; ll a[N]; ll sum[N],mx[N]; ll ans; int main(){ n=read(),k=read(),x=read(); for(int i=1;i<=n;++i) a[i]=read(); if(x<0){ x=-x; k=n-k; } for(int i=1;i<=n;++i) sum[i]=sum[i-1]+a[i]-x; mx[n]=sum[n]; for(int i=n-1;i>=1;--i) mx[i]=max(mx[i+1],sum[i]); ll s=0; for(int i=1;i<=k;++i) s+=a[i]+x; for(int i=k;i<=n;++i){ ll ns=s+mx[i]-sum[i]; ans=max(ans,max(ns,s)); s-=(a[i-k+1]+x); s+=a[i+1]+x; } write(ans); return 0; }