#P12605. 求和
求和
Description
You are given an integer sequence of length .
You can perform the following operations any number of times (possibly, zero):
Select indices such that , and perform the operation: , simultaneously.
Your task is to compute the minimum number of operations needed to make the sum of the prefix sums of equal to the sum of the suffix sums of .
That is, let , you need to make equal to .
Note that can become negative after several operations.
Input Format
The first line contains a single integer .
The second line contains integers .
Output Format
Print a single integer — the minimum number of operations needed.
If it is impossible to satisfy the condition within operations, print .
5
1 2 3 4 5
3
6
2 3 7 4 5 8
-1
Hint
This problem has subtasks.
- Subtask 1 (30 points):
- Subtask 2 (30 points):
- Subtask 3 (5 points):
- Subtask 4 (35 points): No additional constraints
It is guaranteed that for all testcases, .
京公网安备 11011102002149号