Cod sursa(job #495635)
| Utilizator | Data | 26 octombrie 2010 11:28:46 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.39 kb |
#include<stdio.h>
int best[6000001];
int main(){
freopen ("ssm.in", "r", stdin);
freopen ("ssm.out", "w", stdout);
int n, i, k;
scanf("%d ", &n);
for(i=1; i<=n; i++){
scanf("%d ", &k);
if(best[i-1]+k>k)
best[i]=best[i-1]+k;
else
best[i]=k;
}
int max=0;
for(i=1; i<=n; i++)
if(best[i]>max)
max=best[i];
printf("%d ", max);
return 0;
}
