Pagini recente » Cod sursa (job #3266532) | Cod sursa (job #3212147) | Cod sursa (job #1911735) | Cod sursa (job #2554968) | Cod sursa (job #1049111)
#include<fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main()
{
int n,x,i,poz_max,poz_n_st,poz_max_st,maxmax;
long long s;
f>>n;
f>>s;
maxmax=s;
poz_n_st=poz_max=poz_max_st=1;
for(i=2;i<=n;++i)
{
f>>x;
if(s<=0){s=x;poz_n_st=i;}
else s=s+x;
if(s>maxmax){maxmax=s;poz_max=i;poz_max_st=poz_n_st;}
else if(s==maxmax) if(poz_max-poz_max_st<i-poz_n_st){poz_max=i;poz_max_st=poz_n_st;}
}
g<<maxmax<<" "<<poz_max_st<<" "<<poz_max<<"\n";
f.close();
g.close();
return 0;
}