#abc275f. F - Erase Subarrays
F - Erase Subarrays
Score : points
问题描述
你给定一个整数数组 。
你可以执行以下操作任意次数(可能为零次):
- 选择 中的一个非空连续子数组,并将其从数组中删除。
对于每个 ,解决以下问题:
- 找出使 中元素之和等于 的最小操作数。如果无法使 中元素之和等于 ,则输出
-1
。
注意,空数组的元素之和为 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given an integer array .
You may perform the following operation any number of times (possibly zero).
- Choose a nonempty contiguous subarray of , and delete it from the array.
For each , solve the following problem:
- Find the minimum possible number of operations to make the sum of elements of equal . If it is impossible to make the sum of elements of equal , print
-1
instead.
Note that the sum of elements of an empty array is .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer for .
Sample Input 1
4 5
1 2 3 4
Sample Output 1
1
2
1
1
1
The followings are examples of minimum number of operations that achieve the goal.
- For , delete , and the sum of elements of becomes .
- For , delete , then delete , and the sum of elements of becomes .
- For , delete , and the sum of elements of becomes .
- For , delete , and the sum of elements of becomes .
- For , delete , and the sum of elements of becomes .
Sample Input 2
1 5
3
Sample Output 2
-1
-1
0
-1
-1
Sample Input 3
12 20
2 5 6 5 2 1 7 9 7 2 5 5
Sample Output 3
2
1
2
2
1
2
1
2
2
1
2
1
1
1
2
2
1
1
1
1
update @ 2024/3/10 11:35:38