#P1569. [USACO ?] Generic Cow Protests【来源请求】

[USACO ?] Generic Cow Protests【来源请求】

Description

Farmer John’s nn cows gather and line up in a row to stage a protest. The ii-th cow has a rationality value aia_i.

He wants the cows to remain rational; to that end, he plans to partition all the cows into several groups such that within each group the sum of rationality values is at least zero.

Since the cows are arranged in a straight line, each group must be a contiguous segment. Please help John compute the maximum number of groups.

Input Format

The first line contains a positive integer nn, the number of cows.

The next nn lines each contain one integer, the rationality value of each cow.

Output Format

If a valid partition exists, output one line with a single integer, the answer; otherwise output Impossible.

4
2
3
-3
1

3

Hint

Constraints

  • For 30% of the testdata, 1n201 \le n \le 20.
  • For 100% of the testdata, 1n10001 \le n \le 1000, ai105|a_i| \le 10^5.

Translated by ChatGPT 5