Cod sursa(job #362011)
| Utilizator | Data | 7 noiembrie 2009 16:41:43 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include<fstream>
using namespace std;
int best,n,x,start,lung,B,S,L;
int main(){
ifstream f("ssm.in");
ofstream g("ssm.out");
f>>n;
B = -int(2e9);
best=0;
start=1;
int i;
for(i=1;i<=n;++i){
f>>x;
best+=x;
++lung;
if ( B < best ) { B = best; L = i ; S = i - lung + 1 ;}
if( best < 0 ) {
best = 0;
lung = 0;
}
}
g<<B<<" "<<S<<" "<<L;
return 0;
}
