Divide the Sequence

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 119    Accepted Submission(s): 73

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.
 
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
 
Author
ZSTU

贪心。尽量一个个选。考虑到前缀不能为负,可以倒着扫一遍

/* ***********************************************
Author :guanjun
Created Time :2016/8/2 12:04:29
File Name :p512.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 1000010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int a[maxn];
int vis[maxn];
int main()
{
#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
int mark=;
cle(vis);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]<)mark=,vis[i]=;
}
if(!mark){
printf("%d\n",n);continue;
}
ll ans=;
for(int i=n;i>=;i--){
if(vis[i]){
ll sum=a[i];
while(sum<){
i--;
sum+=a[i];
}
}
ans++;
}
printf("%I64d\n",ans);
}
return ;
}

最新文章

  1. @RequestMapping 用法详解之地址映射
  2. python练习之购物车脚本
  3. Zendframework application 引导过程
  4. 使用QGridLayout布局实现翻页效果
  5. Apache的RewriteRule规则详细介绍
  6. java设计模式——接口模式
  7. 代码审查 Code Review
  8. Visual Studio - 提升幸福感的N个快捷键
  9. ipc$爆破密码
  10. lsof基本使用
  11. C# 自动提交到百度ping服务
  12. 用makecert.exe生成一个自签名的证书
  13. 初识servlet--未完成
  14. redis3.0 集群在windows上的配置(转)
  15. hdu4791-Alice&#39;s Print Service
  16. HDU 1527 取石子游戏(威佐夫博弈)
  17. 现代编译原理--第六章(中间树 IR Tree 含源码)
  18. 2018年计划小里程碑(6月)PMI-ACP 敏捷
  19. 关于npm run build打包后css样式中的图片失效的问题(如background)
  20. 导入数据库备份报错1067 – Invalid default value for ‘create_time’

热门文章

  1. js判断图片是否有效
  2. js如何判断数组是Array类型
  3. 专题训练——[kuangbin带你飞]最短路练习
  4. mysql 存储过程批量删除重复数据
  5. 源码学习-String类
  6. MySQL操作示例
  7. Direct3D 12 创建windows窗口
  8. 使用IDEA部署Myeclipse项目----亲测有效
  9. MVC系统学习5——验证
  10. [luoguP1439] 排列LCS问题(DP + 树状数组)