TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

You are given an integer array C (the graceful constraints, illustrated later).

A sequence of real numbers that satisfies the following conditions is considered "graceful":

For each C[i] in C:

If C[i] is negative, the condition is: "The sum of every consecutive -C[i] terms in the sequence must be negative."

If C[i] is positive, the condition is: "The sum of every consecutive C[i] terms in the sequence must be positive."

Find the maximum length possible for a graceful sequence. If there exists an infinitely long fraceful sequence that satisfies all the conditions, print -1.

Input Format

On the first line of input file, an integer T indicates the number of testcases.

Following is T lines of testcases. Each testcase in a line contains precisely the array C.

all number in C is bigger than -1001 and smaller than 1001 and not equal to 0.

All elements in C will be pairwise distinct.

C will contain between 1 and 50 elements, inclusive.

Output Format

For each testcase, output an integer representing the maximum possible length of a valid sequence under the constraint given.

Sample Input 1

3
-2 3
524
1 -1

Sample Output 1

3
-1
0

Hints

For sample input 1, the sequence 2, -3, 2 satisfies all the conditions and its length is 3.

It can be proved that there is no valid sequence with more terms.

Problem Source

Migrated from old NTUJ.

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 200