101291: [AtCoder]ABC129 B - Balance

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

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$.


Sample Input 1

3
1 2 3

Sample Output 1

0

If $T = 2$, $S_1 = 1 + 2 = 3$ and $S_2 = 3$, with the absolute difference of $0$.


Sample Input 2

4
1 3 1 1

Sample 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.


Sample Input 3

8
27 23 76 2 3 5 62 52

Sample Output 3

2

Input

题意翻译

有 $n$ 个正整数,第 $i$ 个数被记作 $w_i$ 。同时,还有一个正整数 $t$ ( $1≤t≤n$ )和两个集合,分别被称作 $s_1$ 和 $s_2$ 。前 $t$ 个数会被放到 $s_1$ 里,其余的数会被放到 $s_2$ 里。记 $a$ 和 $b$ 分别为 $s_1$ 和 $s_2$ 里的所有元素之和,请编程输出 $|a-b|$ 的最小值。

加入题单

上一题 下一题 算法标签: