求正解【MX-X8-T1】「TAOI-3」幸运草
  • 板块灌水区
  • 楼主fluhang_
  • 当前回复7
  • 已保存回复7
  • 发布时间2025/1/31 18:27
  • 上次更新2025/2/1 11:45:34
查看原帖
求正解【MX-X8-T1】「TAOI-3」幸运草
1072112
fluhang_楼主2025/1/31 18:27

我糊的能过但自己算了一下 极限情况应该超时啊

#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;
}
2025/1/31 18:27
加载中...