#P1667. 数列
数列
Description
Given a sequence of length , we call a sequence "perfect" if and only if the sum of any of its subarrays is positive.
You have an operation that can modify the sequence: choose an interval satisfying , where .
Let . Add to and , and subtract from and (if , subtract twice). Find the minimum number of such operations needed to make the sequence perfect.
Input Format
The first line contains an integer .
Lines through : the -th line contains an integer .
Output Format
Output a single integer: the minimum number of operations. If there is no solution, output .
5
13
-3
-4
-5
62
2
Hint
Sample explanation:
First choose the interval , then the sequence becomes . Then choose , the sequence becomes .
Constraints:
- For of the testdata, .
- For of the testdata, ; .
Translated by ChatGPT 5
京公网安备 11011102002149号