Pagini recente » Cod sursa (job #425694) | Cod sursa (job #910165) | Cod sursa (job #860365) | Cod sursa (job #1422258) | Cod sursa (job #1312287)
#include<fstream>
using namespace std;
int main(){
long long s, smax, p, pmax,l,lmax,i,x,n;
ifstream f("ssm.in");
ofstream g("ssm.out");
f>>n;
f>>x;
s=smax=x;
pmax=p=1;
lmax=1;
for(i=2;i<=n;i++)
{
f>>x;
if(s<0)
{
s=x;
p=i;
}
else
s=s+x;
if(s>smax)
{
smax=s;
pmax=p;
lmax=i-p+1;
}
else
if((s==smax) &&(p<pmax))
{
smax=s;
pmax=p;
lmax=i-p+1;
}
}
g<<smax<<" "<<pmax<<" "<<pmax+lmax-1;
}