提交时间:2023-08-14 16:02:56
运行 ID: 98357
#include<bits/stdc++.h> #define N 200010 #define int long long using namespace std; int t,n,k,x; int a[N],s[N]; priority_queue<pair<int,int> >q; signed main(){ while(!q.empty()) q.pop(); cin>>n>>k>>x; if(x<0) x=-x,k=n-k; int pos=1e18,ans=0; q.push(make_pair(0,0)); for(int i=1;i<=n;i++){ cin>>a[i]; s[i]=s[i-1]+a[i]-x; q.push(make_pair(-s[i]-2*x*i,i)); while(i-q.top().second>k) q.pop(); ans=max(ans,s[i]+2*x*i+q.top().first); if(i-k>=0){ pos=min(pos,s[i-k]); ans=max(ans,s[i]-pos+2*k*x); } } cout<<ans<<endl; return 0; }