AtCoder Beginner Contest 129
B
Balance
AtCoder
⌀ 0
原题
← AC →
翻译中…

Problem Statement

翻译中…

We have $N$ weights indexed $1$ to $N$. The mass of the weight indexed $i$ is $W_i$.

翻译中…

We will divide these weights into two groups: the weights with indices not greater than $T$, and those with indices greater than $T$, for some integer $1 \leq T < N$. Let $S_1$ be the sum of the masses of the weights in the former group, and $S_2$ 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 $S_1$ and $S_2$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 100$
  • $1 \leq W_i \leq 100$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
W_1 W_2 ... W_{N-1} W_N

翻译中…

Output

翻译中…

Print the minimum possible absolute difference of $S_1$ and $S_2$.

翻译中…

样例

Input #1
3
1 2 3
Output #1
0
If $T = 2$, $S_1 = 1 + 2 = 3$ and $S_2 = 3$, with the absolute difference of $0$.
Input #2
4
1 3 1 1
Output #2
2
If $T = 2$, $S_1 = 1 + 3 = 4$ and $S_2 = 1 + 1 = 2$, with the absolute difference of $2$. We cannot have a smaller absolute difference.
Input #3
8
27 23 76 2 3 5 62 52
Output #3
2
题目信息
题号
abc129_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。