Cod sursa(job #1049111)
| Utilizator | Data | 6 decembrie 2013 21:47:04 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#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;
}
