Pagini recente » Cod sursa (job #119761) | Cod sursa (job #1082153) | Cod sursa (job #1540406) | Cod sursa (job #2386853) | Cod sursa (job #1765441)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
using namespace std;
int n,s,x,y,a,j;
char *b;
void citire()
{
int l;
fseek(stdin,0,SEEK_END);
l=ftell(stdin);
rewind(stdin);
b=(char*) malloc((l+1)*sizeof(char));
fread(b,sizeof(char),l,stdin);
for (j=0;isdigit(b[j]);j++) n=n*10+b[j]-'0';
}
void det()
{
int i,tmp=0,p=1;
x=1;
for (i=1;i<=n;i++)
{
a=0;
j++;
if (b[j]=='-')
{
for (++j;isdigit(b[j]);j++) a=a*10+b[j]-'0';
a*=-1;
}
else for (;isdigit(b[j]);j++) a=a*10+b[j]-'0';
tmp+=a;
if (tmp>s)
{
s=tmp;
x=p; y=i;
}
else if (tmp==s&&p<x) x=p,y=i;
else if (tmp==s&&p==x&&(i-p<y-x)) x=p,y=i;
if (tmp<0) tmp=0,p=i+1;
}
}
int main()
{
freopen ("ssm.in","r",stdin);
freopen ("ssm.out","w",stdout);
citire();
det();
printf("%i %i %i",s,x,y);
fclose(stdin);
fclose(stdout);
return 0;
}