Problem Description
Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfying that for each subsequence, every its prefix sum is not small than 0.
Input
The input consists of multiple test cases.
Each test case begin with an integer n in a single line.
The next line contains n integers A1,A2⋯An .
1≤n≤1e6
−10000≤A[i]≤10000
You can assume that there is at least one solution.
Each test case begin with an integer n in a single line.
The next line contains n integers A1,A2⋯An .
1≤n≤1e6
−10000≤A[i]≤10000
You can assume that there is at least one solution.
Output
For each test case, output an integer indicates the maximum number of sequence division.
Sample Input
6 1 2 3 4 5 6 4 1 2 -3 0 5 0 0 0 0 0
Sample Output
6 2 5
ps:主要在于倒序消除负数,,还要注意long long
<pre name="code" class="cpp">#include<stdio.h>
#include<string.h>
long long a[1000020];
int main()
{
int t,n;
while(~scanf("%d",&n))
{
memset(a,0,sizeof(a));
int sum=0;
long long num=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
for(int i=n;i>=1;i--)
{
if(a[i]>=0)
{sum++;
a[i]=0;
}
else
{
num=a[i];
a[i-1]+=num;
}
printf("##%d\n",a[i]);
}
printf("%d\n",sum);
}
}
//}
Problem Description
Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfying that for each subsequence, every its prefix sum is not small than 0.
Input
The input consists of multiple test cases.
Each test case begin with an integer n in a single line.
The next line contains n integers A1,A2⋯An .
1≤n≤1e6
−10000≤A[i]≤10000
You can assume that there is at least one solution.
Each test case begin with an integer n in a single line.
The next line contains n integers A1,A2⋯An .
1≤n≤1e6
−10000≤A[i]≤10000
You can assume that there is at least one solution.
Output
For each test case, output an integer indicates the maximum number of sequence division.
Sample Input
6 1 2 3 4 5 6 4 1 2 -3 0 5 0 0 0 0 0
Sample Output
6 2 5