atcoder#ABC129B. [ABC129B] Balance
[ABC129B] Balance
Score : points
Problem Statement
We have weights indexed to . The mass of the weight indexed is .
We will divide these weights into two groups: the weights with indices not greater than , and those with indices greater than , for some integer . Let be the sum of the masses of the weights in the former group, and be the sum of the masses of the weights in the latter group.
Consider all possible such divisions and find the minimum possible absolute difference of and .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible absolute difference of and .
3
1 2 3
0
If , and , with the absolute difference of .
4
1 3 1 1
2
If , and , with the absolute difference of . We cannot have a smaller absolute difference.
8
27 23 76 2 3 5 62 52
2