Pagini recente » Cod sursa (job #1159818) | Cod sursa (job #2569475) | Cod sursa (job #2990620) | Cod sursa (job #2846719) | Cod sursa (job #1284711)
#include<stdio.h>
#include<stdlib.h>
main()
{
FILE *f,*g;
f=fopen("ssm.in","r");
g=fopen("ssm.out","w");
int poz,pozmax,inceputmax,s,smax,inceput,i,j,n,*a;
fscanf(f,"%d ",&n);
a=(int*)malloc(n*sizeof(int));
poz=0;
smax=0;
s=0;
inceputmax=0;
inceput=0;
pozmax=0;
for(i=0;i<n;i++)
{
fscanf(f,"%d ",&a[i]);
s+=a[i];
if(s<0)
{
s=0;
inceput=i+1;
}
if(s>smax)
{
smax=s;
inceputmax=inceput;
pozmax=i;
}
}
fprintf(g,"%d %d %d ",smax,inceputmax,pozmax);
free(a);
return 0;
}