[CF2289D] 邻项反号非负化 (Problem from Yuzhnouralsk)
Problem Statement
You are given an array of integers . In one operation, choose an index () and simultaneously:
- add to ;
- if , add to ;
- replace with .
Find the minimum number of operations to make all elements nonnegative, or output -1 if impossible.
Input
First line: (). Each test case: () and (). Sum of .
Output
Output the minimum number of operations, or -1.
样例
3
3
1 -1 2
2
-1 3
4
5 -3 -2 4
1
-1
4