Cod sursa(job #1916200)

Utilizator dragos03dragos popescu septimiu dragos03 Data 9 martie 2017 08:30:10
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
//se da un vect de n nr int, determ o secv de sum max
#include <fstream>

using namespace std;
int n,a,sumcur,inccur=1,incfin,finfin,maxi=-999999999;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main()
{f>>n;
for(int i=1;i<=n;i++)
{f>>a;
sumcur=sumcur+a;
if(sumcur>maxi)
{incfin=inccur;
finfin=i;
maxi=sumcur;}
if(sumcur<0)
{sumcur=0;
inccur=i+1;}}
g<<maxi<<' '<<incfin<<" "<<finfin;






    return 0;
}