hdu_5783_Divide the Sequence(贪心)

时间:2020-12-10 20:07:48

题目链接:hdu_5783_Divide the Sequence

题意:

给你一个数列,让你分尽可能多的段,并且保证每一段的前缀和都不小于0

题解:

从后往前xjb贪心就行了

 #include<cstdio>

 const int N=1e6+;
int a[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)scanf("%d",a+i);
long long sum=,ans=;
for(int i=n;i>=;i--)
{
sum+=a[i];
if(sum>=)ans++,sum=;
}
printf("%lld\n",ans);
}
return ;
}