#P9207. 灭罪「正直者之死」
灭罪「正直者之死」
Background
Upright people, strong and unyielding people, people who are fair and honest.
Such people probably suffer losses everywhere, but this view is probably seen from the eyes of cheaters. Upright people, even after death, are still the most respected.
Problem Description
There is a calculator that uses a -bit signed integer type to store numbers. That is, the range a variable can represent is . Now we want to use this calculator to compute the sum of a sequence of numbers . The pseudocode is as follows:

Because of a strange property, if the result of adding two variables falls outside , that is, an overflow happens, then this calculator will freeze and can never compute again.
To prevent this, a workaround is to change the order of the . It is easy to see that this will not change the final sum.
However, there may be no ordering that allows the computer to finish summing all numbers without crashing. Still, we hope to compute the sum of as many numbers as possible.
Input Format
The first line contains two integers , representing the number of elements and the integer bit width.
The second line contains integers .
Output Format
Output one integer in a single line, meaning the maximum number of values whose sum can be computed.
3 3
1 2 3
2
10 4
-3 5 6 -4 5 3 -4 1 -1 0
9
Hint
Sample Explanation
- For sample , one optimal plan is , so that there is no overflow when computing the first two numbers.
- For sample , one optimal plan is , so that there is no overflow when computing the first numbers.
Constraints and Notes
For all testdata, it is guaranteed that , , .
Translated by ChatGPT 5