题目描述:
A,B两团体把苹果分为两堆,A盼望依照它的盘算规矩平分苹果,他的盘算规矩是依照二进制加法盘算,而且不盘算走位,12+5=9(1100+0101=9), B的盘算规矩是十进制加法,包含畸形进位,B盼望在满意A的情形下获取苹果分量最多,输入苹果的数目跟每个苹果分量,输出满意A的情形下获取的苹果总分量, 假如无奈满意A的请求,输出-1。
int main() {
int n;
vector<int> rVec;
cin >> n;
while (n)
{
n--;
int weight;
cin >> weight;
rVec.push_back(weight);
}
int minWeight = 10001;
int aWeight = 0, bWeight = 0;
for (auto x : rVec)
{
aWeight ^= x;
bWeight += x;
minWeight = min(minWeight, x);
}
if (aWeight == 0)
{
cout << bWeight - minWeight << endl;
}
else
{
cout << -1 << endl;