B. 折断木棍 / Break a Stick

    传统题 1000ms 256MiB

折断木棍 / Break a Stick

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

Problem Statement

There is one stick. This stick has N1N-1 notches, which divide it into NN parts.

The lengths of the parts are L1,L2,,LNL_1,L_2,\dots,L_N in order from one end.

When choosing one notch and breaking the stick there to obtain two sticks, find the minimum possible absolute value of the difference between the lengths of the two resulting sticks.

Here, the width of a notch can be ignored, and the length of each resulting stick is the sum of the lengths of the parts it contains.

Constraints

  • 2N1002 \leq N \leq 100
  • 1Li1051 \leq L_i \leq 10^5
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • NN
  • L1L_1 L2L_2 \dots LNL_N

Output

Output the answer.

4
5 2 3 8
2

Breaking the stick at each notch results in the following:

  • Breaking at the first notch from the end results in two sticks of lengths 55 and 1313, with an absolute difference of 88.
  • Breaking at the second notch from the end results in two sticks of lengths 77 and 1111, with an absolute difference of 44.
  • Breaking at the third notch from the end results in two sticks of lengths 1010 and 88, with an absolute difference of 22.
7
31 41 59 26 53 58 97
51
10
67011 35764 33042 24098 63738 98760 17199 68579 21812 45408
28105

ABC472 赛后模拟赛 ✅

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-8-22 21:40
结束于
2026-9-5 21:40
持续时间
336 小时
主持人
参赛人数
52