#C2905. Minimum Dimmer Uses
Minimum Dimmer Uses
Minimum Dimmer Uses
You are given a street with n segments, where the brightness of the i-th segment is given by an integer. Your task is to compute the minimum number of dimmer device uses required to make the total brightness of the street exactly zero. Each use of the dimmer device changes the brightness by 1 unit.
In other words, if the sum of the brightness values is S, then the answer is:
\( |S| \)
For example, if the input is 5
segments with brightness values [3, 1, -2, 4, -1]
, the sum is 5
, so you need 5 dimmer uses. Solve the problem using the standard input and output.
inputFormat
The first line of the input contains a single integer n indicating the number of segments. The second line contains n space-separated integers representing the brightness of each segment.
outputFormat
Output a single integer representing the minimum number of dimmer uses required to make the total brightness equal to zero.
## sample5
3 1 -2 4 -1
5
</p>