提交时间:2023-08-14 12:24:28

运行 ID: 98164

#include<bits/stdc++.h> #define int long long using namespace std; inline int read() { int f=1,x=0; char c=getchar(); while(c>'9'||c<'0') { if(c=='-') f*=-1; c=getchar(); } while(c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); } return x*f; } const int N=2e5+7; int s[N],n,k,x,ans,now,nowans; inline get_(int len) { if(len<=k) return len*x; if(len>k) return k*x-(len-k)*x; } const int OP=50; signed main() { n=read(); k=read(); x=read(); if(x<0) { x*=-1; k=n-k; } for(int i=1;i<=n;i++) s[i]=s[i-1]+read(); ans=0; nowans=0; for(int i=1;i<=n;i++) { if(s[i]+get_(i)>ans) { nowans=ans=s[i]+get_(i); now=i; } } for(int l=2;l<=n;l++) { ans=max(ans,nowans=s[now]-s[l-1]+get_(now-l+1)); int opt=now; for(int r=opt+1;r<=min(n,opt+OP);r++) { if(s[r]-s[l-1]+get_(r-l+1)>nowans) { nowans=s[r]-s[l-1]+get_(r-l+1); now=r; } } ans=max(ans,nowans); } printf("%lld",ans); return 0; }