Pagini recente » Cod sursa (job #2597391) | Cod sursa (job #2597384) | Cod sursa (job #2597349) | Cod sursa (job #339903)
Cod sursa(job #339903)
#include <stdio.h>
#define nmax 6000000
int a[nmax], n, min, max, pozmin, pozmax, i;
int main() {
freopen ("ssm.in", "r", stdin);
freopen ("ssm.out", "w", stdout);
scanf ("%d", &n);
for (i = 1; i <= n; ++i)
scanf ("%d", &a[i]);
pozmin=0;
min=0;
for (i = 1; i <= n; ++i) {
a[i] += a[i-1];
if ((a[i] - min) > max ) {
max = a[i] - min;
pozmax = i;
}
if (a[i] < min) {
min = a[i];
pozmin = i;
}
}
printf ("%d %d %d", max, pozmin + 1, pozmax);
return 0;
}