提交时间:2023-08-14 11:58:55
运行 ID: 98079
#include<cstdio> #include<cstring> #include<algorithm> const int N=2e5+1;int n,k,x,a[N];long long r;int d[N]; static void dfs(int p,int f){if(p==k+1){long long s=0,mn=1e18,mx=-mn; for(int i=1;i<=n;i++){s+=a[i]+(d[i]?x:-x);if(s<0)s=0; mx=std::max(mx,s);mn=std::min(mn,s);}r=std::max(r,mx-mn);} for(int i=f+1;i<=n;i++){d[i]=1;dfs(p+1,i);d[i]=0;}} int main(){scanf("%d%d%d",&n,&k,&x);for(int i=1;i<=n;i++)scanf("%d",a+i);dfs(1,0);printf("%lld\n",r);}