动态规划的水题,不多说了。
#include<cstdio>
int n,p,f[100001],max;
int main()
{
freopen("profits.in","r",stdin);
freopen("profits.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&p);
f[i]=p>(f[i-1]+p)?p:(f[i-1]+p);
}
max=f[1];
for(int i=1;i<=n;i++)
max=max>f[i]?max:f[i];
printf("%d",max);
fclose(stdin);
fclose(stdout);
return 0;
}