Pagini recente » Cod sursa (job #1047592) | Cod sursa (job #1006006) | Cod sursa (job #1396046) | Clasament utcn-2023 | Cod sursa (job #1284740)
#include<stdio.h>
#include<stdlib.h>
main()
{
FILE *f,*g;
f=fopen("ssm.in","r");
g=fopen("ssm.out","w");
int pozneg,neg,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;
}
if((a[i]>neg)&&(a[i]<1)){
neg=a[i];
pozneg=i;
}
}
if(smax>0){
fprintf(g,"%d %d %d ",smax,inceputmax+1,pozmax+1);
}
else{
fprintf(g,"%d %d %d ",neg,pozneg,pozneg);
}
free(a);
return 0;
}