Divide the Sequence
来源:互联网 发布:橡胶木家具 价格算法 编辑:程序博客网 时间:2024/05/10 06:05
Divide the Sequence
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 70 Accepted Submission(s): 41
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 containsn 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
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
61 2 3 4 5 641 2 -3 050 0 0 0 0
Sample Output
625把长度为n的序列分成尽量多的连续段,使得每一段的每个前缀和都不小于0。保证有解。 从后往前贪心分段即可。#include<stdio.h>#include<iostream>using namespace std;#include<string.h>#define maxn 10000long long a[1000020];int main(){ int n,m,k; while(scanf("%d",&n)!=-1) { for(int i=0; i<n; i++) scanf("%lld",&a[i]); int sum=0; for(int i=n-1; i>=0; i--) { if(a[i]>=0) { sum++; } else if(a[i]<0) { a[i-1]=a[i-1]+a[i]; } } printf("%d\n",sum); }}
0 0
- Divide the Sequence
- Divide the Sequence
- Divide the Sequence
- hdu 5783 Divide the Sequence
- Divide the Sequence hdu 5783
- hdu 5783 Divide the Sequence
- HDU 5783 Divide the Sequence
- 【HDU】5783 Divide the Sequence
- hdu 5783 Divide the Sequence
- HDU 5783 Divide the Sequence
- HDU5783 Divide the Sequence(贪心)
- HDU 5783 Divide the Sequence
- hdu 5783 Divide the Sequence【水题】
- HDU 5783 Divide the Sequence(水题)
- 2016多校5 hdoj5783 Divide the Sequence
- HDOJ 5783 Divide the Sequence(贪心)
- HDU 5783 Divide the Sequence 【贪心】
- 【HDOJ5783】Divide the Sequence(贪心)
- 【MySQL】MySQL中针对大数据量常用技术
- Leetcode 84. Largest Rectangle in Histogram
- 训练与测试
- OpenCV之直方图均衡化原理详解
- mysqldump使用方法
- Divide the Sequence
- mysqlbinlog 恢复指定表
- java回忆录—数据类型的魅力
- iOS CoreData入门
- JQuery 返回顶部
- OracleOraDb11g_home1TNSListener服务启动后又自动停止
- mysqldump默认参数add-drop-table
- linux下简单配置zlib软件
- SQLi Labs Lesson6