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 A_{1},A_{2}\cdots A_{n}

.
1 \leq n \leq 1e6

-10000 \leq A[i] \leq 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的;
思路就是从后往前遍历,要想分的最多那么有整数直接,当成一个数列就行了,有负数往前递加直到和为零。这里特别注意,数据要用long long要不然会溢出的
*/ #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#define N 1000005
#define M (1<<15)+5
#define INF 0x3f3f3f
using namespace std;
long long n,a[N],sum;
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%lld",&n)!=EOF)
{
memset(a,,sizeof(a));
for(int i=;i<n;i++)
{
scanf("%lld",&a[i]);
}
long long cur=;
for(int i=n-;i>=;i--)//这个是首位枚举
{
if(a[i]>=)
cur++;
else
{
sum=;
for(;i>=;i--)
{
sum+=a[i];
if(sum>=)
{
cur++;
break;
}
}
}
}
printf("%lld\n",cur);
}
return ;
}
 

最新文章

  1. 安装了ruby后怎么安装sass
  2. 关于AlertDialog.Builder(Context context)中所应传入的context
  3. css3实现翻页卡片
  4. js控制select下拉列表数据绑定
  5. 使用Spring Data JPA查询时,报result returns more than one elements异常
  6. 解决document.onclick在IE下用不了或无效的问题
  7. Vijos P1459 车展 treap求任意区间中位数
  8. C/C++:[2]enum-枚举量声明、定义和使用
  9. Echarts个人实例
  10. 【HDU 4612 Warm up】BCC 树的直径
  11. Linux之yum
  12. c语言函数作业
  13. tkinter中树状结构的建立(十四)
  14. python--装饰器(附偏函数、断言)
  15. Sql server2012转sql server2008步骤经验总结(转)
  16. 展开被 SpringBoot 玩的日子 《 四 》 Session 会话共享
  17. 在anguler项目中引用fullCalendar
  18. loadrunner&#160;运行脚本-Run-time&#160;Settings之Preferences设置
  19. django常用命令
  20. IIS中“绑定”,“IP地址全部未分配”到底是个什么玩意

热门文章

  1. STM32F103X 开发环境搭建
  2. js 操作数组(过滤对应数据)
  3. AngularJS系列-翻译官网
  4. linux free命令解读
  5. unset与unlink
  6. Maximum repetition substring (poj3693 后缀数组求重复次数最多的连续重复子串)
  7. hdu1512 Monkey King(左偏树 + 并查集)
  8. cs224d 自然语言处理作业 problem set3 (一) 实现Recursive Nerual Net Work 递归神经网络
  9. 我的第一篇blog—— 一起来赛马呀
  10. jQuery实现web页面固定列表搜索