cswork / OA打开练习工作台

JPMorgan ChaseOA #3

Equalize Consignment Quantities

估计简单可在线判题

考点(AI 标注)前缀和区间

Cut once between adjacent categories to form two non-empty contiguous shipments; one operation adds one to or subtracts one from the quantity of any category, but every quantity must stay positive. Find the minimum number of operations to make the two shipments' totals equal.

输入格式

The first line contains n, followed by n values of quantity. 2≤n≤300000, 1≤quantity[i]≤2000000000.

输出格式

Output a single integer answer.

样例 1

输入:

3
1 4 4

输出:

1

样例 2

输入:

5
3 3 6 3 9

输出:

0

样例 3

输入:

3
4 5 7

输出:

2

样例说明

The outputs of the three public examples are, in order: 1; 0; 2. These answers have been checked by independent enumeration or direct simulation.