Codeforces Round 1097 (Div. 2, Based on Zhili Cup 2026)
A
Zhily and Array Operating
Codeforces
800
原题
←B →
翻译中…

Deep in the wilderness, Zhily and Jily discovered a series of gathering places that contain abstract logic. Some of these gathering places harbor inconsistent errors in their logic, which may collapse at any moment. They hope to transmit logic between adjacent gathering places through reasonable transfer arrangements so that as many gathering places as possible can eventually restore logical stability.

翻译中…

You are given an array $a$ of $n$ integers. You can perform the following operation any number of times:

翻译中…
  • Choose an index $i$ ($1 \le i \lt n$) and assign $a_i\gets a_i+a_{i+1}$.
翻译中…

Each index can be chosen at most once.

翻译中…

Find the maximum number of positive integers in the final array after all operations.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2\leq n \leq 2\cdot 10^5$).

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($-10^9\leq a_i\leq 10^9$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.

翻译中…

Output

翻译中…

For each test case, you should output a single line containing an integer $k$, the number of positive numbers in the final sequence.

翻译中…

Note

翻译中…

In the first test case, the array $a$ is operated on by the following process:

翻译中…

$[0,-1,3,-3,0]\to [0,\color{red}{2},3,-3,0]\to [\color{red}{2},2,3,-3,0]$.

翻译中…

There are $3$ positive numbers in the final array, and it can be proven that this is the maximum count of positive integers.

翻译中…

In the second test case, the final array can be:$[4,4,6,5,3]$, which is operated on by the following process:

翻译中…

$[0,-2,1,2,3]\to [0,-2,1,\color{red}{5},3]\to [0,-2,\color{red}{6},5,3]\to [0,\color{red}{4},6,5,3]\to [\color{red}{4},4,6,5,3]$.

翻译中…

In the third test case, the final array can be:$[1,1,1,1,0]$, which is operated on by the following process:

翻译中…

$[0,1,0,1,0]\to [\color{red}{1},1,0,1,0]\to [1,1,\color{red}{1},1,0]$.

翻译中…

样例

Input #1
4
5
0 -1 3 -3 0
5
0 -2 1 2 3
5
0 1 0 1 0
2
1000000000 -1000000000
Output #1
3
5
4
1
InputCopy OutputCopy
题目信息
题号
2224A
时间限制
1 s
内存限制
512 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。