找一个x,让它分为sum*2
找到sum
好了
const int N=2e5+7; int n,a[N]; map<int,int>mp; void solve(){ mp.clear(); cin>>n;int sum=0; for(int i=1;i<=n+2;++i){ cin>>a[i]; sum+=a[i]; mp[a[i]]++; } int flag=0; for(int i=1;i<=n+2;++i){ int now=sum-a[i]; if(now&1) continue; if(mp[now>>1]>0){ if(a[i]==(now>>1)&&mp[a[i]]==1) continue;//相同情况 不唯一 int f=0,ff=0; for(int j=1;j<=n+2;++j){ if(a[j]==(now>>1)&&f==0){ f=1;continue; } if(a[j]==a[i]&&ff==0){ ff=1;continue; } cout<<a[j]<<" "; } flag=1; break; } } if(!flag){ cout<<"-1 "; return ; } cout<<" "; }