#P10911. [蓝桥杯 2024 国 B] 数位翻转
[蓝桥杯 2024 国 B] 数位翻转
Problem Description
Xiaoming created a function to reverse the binary digits of (with no leading ). For example, , because , and after reversing it left to right, it becomes . Another example: , , and , and so on.
Xiaoming randomly generated an integer array of length . He wants to know: in this array, if you choose at most disjoint intervals and reverse the binary digits of the numbers inside these intervals (change to ), what is the maximum possible sum of the entire array?
Input Format
The input has lines.
The first line contains two positive integers .
The second line contains integers separated by spaces.
Output Format
Output line containing one integer, which is the answer.
5 3
11 12 13 14 15
67
6 2
23 8 11 19 16 35
134
Hint
[Sample Explanation 1]
Flip only , and the sum is .
[Sample Explanation 2]
Flip intervals and , and the sum is .
[Constraints]
For of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that , and .
Translated by ChatGPT 5