[Solution] Zero-Sum Prefixes Codeforces Solution
The score of an array is defined as the number of indices () such that .
You are given an array of length . You can perform the following operation multiple times:
- select an index () such that ;
- then replace by an arbitrary integer.
What is the maximum possible score of that can be obtained by performing a sequence of such operations?
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases.
The first line of each test case contains one integer () — the length of the array .
The second line of each test case contains integers () — array .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print the maximum possible score of the array after performing a sequence of operations.
In the first test case, it is optimal to change the value of to in one operation.
The resulting array will be , with a score of :
- ;
- ;
- .
In the second test case, it is optimal to change the value of to , giving us an array with a score of .
In the third test case, it is not necessary to perform any operations.
No comments:
Post a Comment