Cod sursa(job #1237544)

Utilizator Stefanel55Buracu Stefan Stefanel55 Data 4 octombrie 2014 11:57:31
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>

using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int nr,i,n,suma=-2000000000,sumamax=-2000000000,pozi,pozi2,pozf;
int main()
{
    in>>n;
    for (i=1; i<=n; i++)
    {
        f>>nr;
        if (suma<0)
        suma=nr, pozi=i;
        else
            suma+=nr;

        if (suma>sumamax)
            sumamax=suma, pozi2=pozi, pozf=i;
    }
  out<<sumamax<<" "<<pozi2<<" "<< pozf;
    return 0;
}