我糊的能过但自己算了一下 极限情况应该超时啊
#include<bits/stdc++.h>
#define int long long
#define fast register int
using namespace std;
const int N=1e5+100;
int a[N];
int n,x,l=-1,r=-1,cnt[N],cnt1[N],f=0,ans=-0x7f7f7f7f,ans1=0;
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>x;
for (fast i=1;i<=n;i++){
cin>>a[i];
ans1+=a[i];
if (a[i]<=x){
if (l==-1) l=1,r=-1,f++;
cnt[f]+=x-a[i];
}
if (a[i]>x){
if (r==-1) r=1,l=-1,f++;
cnt[f]+=x-a[i];
}
}
for (fast i=1;i<=f;i++){
int qwq=0;
for (fast j=i;j<=f;j++){
qwq+=cnt[j];
ans=max(ans,qwq);
}
}
if (ans<=0){
cout<<ans1;
}
else cout<<ans1+ans;
return 0;
}