Cod sursa(job #2150206)
| Utilizator | Data | 3 martie 2018 12:44:49 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream >
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int main()
{
int n,S,smax,stmax,drmax,st,x;
fin >> n>> x;
S=smax=x;
stmax=drmax=st=1;
for (int i=2;i<=n;i++){
if (S<0){
S=0;
st=i;
}
fin >> x;
S=S+x;
if (S>smax){
smax=S;
stmax=st;
drmax=i;
}
}
fout << smax <<" "<< stmax << " "<<drmax;
return 0;
}
