若a ^ b ^ c = faultSum,那么faultSum == 0时,即可产生上面的平分方案。说明可以满足二进制平分
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> weight(n);
for(int i=0;i<n;i++)
{
cin>>weight[i];
}
sort(weight.begin(),weight.end());
int fault=weight[0];
int correct=weight[0];
for(int i=0;i<n;i++)
{
fault^=weight[i];
correct+=weight[i];
}
if(fault==0)
{cout<<correct-weight[0];}
else
{
cout<<-1;
}
return 0;
}