首页 > 其他 > 详细

Divide the Sequence

时间:2016-08-07 09:39:18      阅读:194      评论:0      收藏:0      [点我收藏+]

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

 

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.
1n1e6
10000A[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

 

 

题意:

给定一串数字分成若干份,使任意份的任意前缀和都不为负。

 

从后向前遍历贪心。

 

附AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 int a[1000010];
 9 
10 int main(){
11     int n;
12     while(~scanf("%d",&n)){
13         int sum=n-1;
14         for(int i=0;i<n;i++){
15             scanf("%d",&a[i]);
16         }
17         int t=0;
18         while(sum>=0){
19             long long ans=0;
20             ans+=a[sum];
21             while(ans<0){
22                 sum--;
23                 ans+=a[sum];
24             }
25             t++;
26             sum--;
27         }
28         printf("%I64d\n",t);
29 }
30     return 0;
31 }

 

Divide the Sequence

原文:http://www.cnblogs.com/Kiven5197/p/5745543.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!