Pagini recente » Cod sursa (job #1573414) | Cod sursa (job #1909848) | Cod sursa (job #2270945) | Cod sursa (job #116314) | Cod sursa (job #615844)
Cod sursa(job #615844)
#include<fstream>
#include<cstdio>
#include<climits>
//int s[6000005]={0};
int main()
{
std::ifstream fin("ssm.in");
std::ofstream fout("ssm.out");
int n;
fin>>n;
int x,beg,end;
int min=0,best,ii=0,bestSum=INT_MIN;
int s=0;
int i=0;
fin>>x;
s=x;
min=x;
bestSum=best=s;
beg=0;
end=0;
for(i=1;i<n;++i)
{
fin>>x;
s+=x;
best=s-min;
if(min>s)
{
min=s;
ii=i;
}
if(bestSum<best || (bestSum==best && i+beg<end+ii+1))
{
bestSum=best;
beg=ii+1;
end=i;
}
}
if(beg>end)
beg=end;
fout<<bestSum<<' '<<beg+1<<' '<<end+1<<'\n';
return 0;
}