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 ;
}
 

HDU 5783 Divide the Sequence (训练题002 B)的更多相关文章

  1. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5783 Divide the Sequence (贪心)

    Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...

  3. hdu 5783 Divide the Sequence 贪心

    Divide the Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...

  4. HDU 5783 Divide the Sequence

    Divide the Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. 【贪心】HDU 5783 Divide the Sequence

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 题目大意: 把一个N个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...

  6. HDU 5791 Two(训练题002 F)

    Description Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and ...

  7. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

  8. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

  9. HDU 5805 NanoApe Loves Sequence (思维题) BestCoder Round #86 1002

    题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的 ...

随机推荐

  1. jQuery: Callbacks

    jQuery 中提供了一个Callback的工具类Callbacks,它提供了一个Callback Chain.使用它可以在一个chain上来执行相关操作.它也是jQuery中的ajax, Defer ...

  2. 翻译:MLAPP(2.1节)

    笔者:尝试翻译MLAPP(Machine Learning: a Probabilistic Perspective)一书,供机器学习的学者参考,如有错误理解之处请指出,不胜感激!(如需转载,请联系本 ...

  3. 命令行参数处理-getopt()和getopt_long()

    在实际编程当中,自己编写代码处理命令行参数是比较麻烦且易出错的.一般我们会直接使用getopt()和getopt_long()函数,下文将介绍具体的使用方法. getopt() getopt()用于处 ...

  4. Linux下Apache https认证

    参考:http://kyfxbl.iteye.com/blog/1910891 http://showerlee.blog.51cto.com/2047005/1266712 一.环境 httpd:A ...

  5. Python实战之文件操作的详细简单练习

    ['_CHUNK_SIZE', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__' ...

  6. Linux vi 退出&保存/不保存

    无论是否退出 vi,均可保存所做的工作.按 ESC 键,确定 vi 是否处于命令模式. 操作   键入 保存,但不退出vi                          :w 保存并退出vi    ...

  7. 邮件实现详解(二)------手工体验smtp和pop3协议

    上篇博客我们简单介绍了电子邮件的发送和接收过程,对参与其中的邮件服务器,邮件客户端软件,邮件传输协议也有简单的介绍.我们知道电子邮件需要在邮件客户端和邮件服务器之间,以及两个邮件服务器之间进行传递必须 ...

  8. C#调用存储过程带输出参数或返回值

    CREATE PROCEDURE [dbo].[GetNameById] @studentid varchar(8), @studentname nvarchar(50) OUTPUT AS BEGI ...

  9. Win10打补丁KB4022725出现0x80073712错误

    周末从老家回来折腾电脑,发现又收到了一大堆补丁,其中包括6月累积更新KB4022725.在安装过程中,一不小心手滑碰到了插线板,电脑断电了!!尼玛,这是要悲催的节奏么? 重新上完电开机,开机界面显示正 ...

  10. MySQL(十五)之数据备份中mysqldump详解

    前言 其实前面一篇数据备份已经是非常的详细了,这里我想单独的讲解一下mysqldump,相信很多程序员都是用过这个命令的! 一.MySQL数据库的备份与还原 1.1.MySQL数据库备份 1)语法 m ...