Cod sursa(job #2073582)
Utilizator | Data | 23 noiembrie 2017 12:48:19 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n;
int s,maxi;
int main()
{ int x,i,c,f,ind;
fin>>n;
fin>>x;
maxi=x;
s+=x;
c=1; f=1;
ind=1;
for(i=2;i<=n;++i)
{ fin>>x;
if(s<0) {s=0;
ind=i;
}
s+=x;
if(s>maxi)
{ maxi=s;
f=i;
c=ind;
}
}
fout<<maxi<<" "<<c<<" "<<f;
return 0;
}