传统题 1000ms 256MiB

Balance

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

Problem Statement

We have NN weights indexed 11 to NN. The mass of the weight indexed ii is WiW_i.

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

Constraints

  • 2N1002 \leq N \leq 100
  • 1Wi1001 \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 S1S_1 and S2S_2.

Sample Input 1

3
1 2 3

Sample Output 1

0

If T=2T = 2, S1=1+2=3S_1 = 1 + 2 = 3 and S2=3S_2 = 3, with the absolute difference of 00.

Sample Input 2

4
1 3 1 1

Sample Output 2

2

If T=2T = 2, S1=1+3=4S_1 = 1 + 3 = 4 and S2=1+1=2S_2 = 1 + 1 = 2, with the absolute difference of 22. We cannot have a smaller absolute difference.

Sample Input 3

8
27 23 76 2 3 5 62 52

Sample Output 3

2

2024暑期集训第四周小测

未参加
状态
已结束
规则
ACM/ICPC
题目
6
开始于
2024-7-24 19:00
结束于
2024-7-24 21:00
持续时间
2 小时
主持人
参赛人数
35