Huawei OD Computer Test Real Questions-Dividing Building Blocks-2023 OD Unified Examination (Paper B)

Topic description:

Solo and koko are two brothers. Their mother gave them a lot of building blocks, each with its own weight. Now they want to separate the blocks into two piles. The elder brother Solo is responsible for the distribution. The younger brother koko requires that the total weight of the building blocks obtained by the two people is "equal" (according to Koko's logic). The number can be different, otherwise he will cry, but koko will only convert the two numbers into binary first and then add them. , and the carry is always forgotten (every carry is forgotten). For example, when 25 (11101) is added to 11 (1011), the calculation result obtained by koko is 18 (10010):

 11001

+01011

--------

 10010

Solo wants to maximize the total weight of the blocks he gets as much as possible without making koko cry.

Enter description:

3

3 5 6

The first line is an integer N (2≤N≤100), indicating how many building blocks there are; the second line is N integers Ci (1≤Ci≤106) separated by spaces, indicating the weight of the i-th building block. Output description:

11

Let koko not cry and output the maximum total weight of the building blocks that Solo can obtain; otherwise, output "NO".

Additional instructions:

If you can prevent koko from crying, output the total weight of the blocks that Solo can obtain, otherwise output -1.

The sample output is 11.

Explanation: Solo can obtain two building blocks with weights of 5 and 6. 5 is converted into binary system 101, and 6 is converted into binary system 110. According to koko's calculation method (forgetting the carry), the result is 11 (binary system). Koko gets a building block with a weight of 3 and converts it into binary bit 11 (two

Guess you like

Origin blog.csdn.net/2301_76848549/article/details/133219373