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
求最多分几段和都大于等于0,随便搞搞就好了
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
using namespace std;
typedef __int64 LL;
const int low(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
int T, n, x;
int main()
{
//scanf("%d", &T);
//while (T--)
while (scanf("%d", &n) != EOF)
{
stack<int> p;
rep(i, 1, n)
{
scanf("%d", &x);
if (x >= 0) p.push(x);
else
{
while (x < 0)
{
x += p.top();
p.pop();
}
p.push(x);
}
}
printf("%d\n", p.size());
}
return 0;
}