Pagini recente » Clasamentul arhivei de probleme | Cod sursa (job #1669114) | Cod sursa (job #1669105) | Cod sursa (job #3303853) | Cod sursa (job #1669111)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int nrmax,i,a[6000001],n,pi,S[6000001],pf,smax,x,y;
int main ()
{
fin>>n;
for(i=1;i<=n;i++)
{
fin>>a[i];
}
nrmax=a[1];
x=1;
S[0]=0;
pi=1;
pf=1;
for(i=1;i<=n;i++)
{
if(a[i]+S[i-1]>0)
{
S[i]=S[i-1]+a[i];
if(S[i]>smax)
{
pf=i;
smax=S[i];
}
}
else
{
S[i]=0;
pi=i+1;
}
if(a[i]>nrmax)
{
nrmax=a[i];
x=i;
}
}
if(smax>=0)
{
fout<<smax<<" "<<pi<<" "<<pf;
}
else
{
fout<<nrmax<<" "<<x<<" "<<x;
}
fin.close();
fout.close();
return 0;
}