Non-negative Partial Sums
Time limit3sMemory limit128 MB
Given a cyclic array, count how many rotations make every prefix sum of the rotated sequence non-negative.
- Level
Medium5 of 10
- Topics
- Prefix sum, Array
- Solved
- No attempts yet
Problem
You are given a sequence of numbers . A cyclic shift by positions () produces the sequence Count how many of the cyclic shifts satisfy the following condition: the sum of the first numbers of the shifted sequence is greater than or equal to zero for every with .
Input
The input contains several test cases.
Each test case consists of two lines. The first line contains the integer (), the number of integers in the sequence. The second line contains integers () describing the sequence.
The input ends with a line containing a single .
Output
For each test case, print one line containing the number of cyclic shifts of the given sequence that satisfy the condition above.