Pagini recente » Cod sursa (job #903997) | Cod sursa (job #446668) | Cod sursa (job #129297) | Cod sursa (job #810122) | Cod sursa (job #2176135)
#include <stdio.h>
#include <limits.h>
int a[6000010];
int main()
{
FILE *f=fopen("ssm.in", "r");
int n, s=-1, smax=INT_MIN, imax, lmax, l=0;
fscanf(f, "%d", &n);
for (int i=0; i<n; i++)
fscanf(f, "%d", &a[i]);
fclose(f);
for (int i=0; i<n; i++)
{
if (a[i]+s<0 || s<0)
{
s=a[i];
l=1;
}
else
s+=a[i],l++;
if (s>smax)
smax=s,imax=i,lmax=l;
}
FILE *g=fopen("ssm.out", "w");
fprintf(g, "%d %d %d", smax, imax-lmax+2, imax+1);
fclose(g);
return 0;
}