Cod sursa(job #1075011)
| Utilizator | Data | 8 ianuarie 2014 13:12:59 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include<cstdio>
#include<climits>
using namespace std;
int i, n, sc, poz_init, poz_fin, poz_c, smax, x;
int main(){
freopen("ssm.in","r",stdin);
freopen("ssm.out","w",stdout);
scanf("%d", &n);
poz_init=1; poz_fin=1; poz_c=1;
sc=INT_MIN; smax=INT_MIN;
for (i=1;i<=n;i++) {
scanf("%d", &x);
if ((sc<0)&&(sc<x)) {poz_c=i; sc=x;}
else sc+=x;
if (sc>smax) {
smax=sc;
poz_init=poz_c; poz_fin=i;
}
}
printf("%d\n", smax);
return 0;
}
