传统题 1000ms 256MiB

B - Balance

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

B - Balance

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:

NN

W1W_1 W2W_2 ...... WN1W_{N-1} WNW_N

Output

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


3
1 2 3
0

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


4
1 3 1 1
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.


8
27 23 76 2 3 5 62 52
2

2024春季入门组刷题营(二)

未参加
状态
已结束
规则
IOI
题目
8
开始于
2024-3-17 13:00
结束于
2024-3-17 15:00
持续时间
2 小时
主持人
参赛人数
11