Pagini recente » Cod sursa (job #140170) | Cod sursa (job #2375866) | Cod sursa (job #236299) | Cod sursa (job #2832676) | Cod sursa (job #1163197)
#include<cstdio>
#include<algorithm>
#include<vector>
#define M -2000000000
using namespace std;
FILE *f=fopen("ssm.in","r");
FILE *g=fopen("ssm.out","w");
int maxx=M,s,x,i,n,maxel=M,pozel,nr,pozsf,nrmax;
vector<int>a,sol;
int main()
{
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
{
fscanf(f,"%d",&x);
if(x>maxel)
{maxel=x;pozel=i;}
s+=x;
if(s<0){s=0;nr=0;}
else
{ nr++;
if(maxx<s)
{pozsf=i;maxx=s;nrmax=nr;}
}
}
if(s!=0)
fprintf(g,"%d %d %d",maxx,pozsf-nrmax+1,pozsf);
else
{
fprintf(g,"%d %d %d",maxel,pozel,pozel);
}
return 0;
}