Pagini recente » Cod sursa (job #1261554) | Cod sursa (job #1091995) | Cod sursa (job #2978915) | Cod sursa (job #808286) | Cod sursa (job #291967)
Cod sursa(job #291967)
#include<fstream.h>
int main()
{
long long i,n,lmax,rmax,l,r;
long long s,max,x;
ifstream f("ssm.in");
f>>n;
max=1;
max=(long long)-1*max<<33;
s=0;
for (i=1;i<=n;i++)
{
f>>x;
if (s>=0) s+=x;
else {
l=i;
s=x;
}
if (s>max) {
max=s;
lmax=l;
rmax=i;
}
}
ofstream g("ssm.out");
cout<<max<<' '<<lmax<<' '<<rmax;
g.close();
f.close();
return 0;
}