Cod sursa(job #2162444)

Utilizator RazvanGutaGuta Razvan Alexandru RazvanGuta Data 12 martie 2018 11:09:06
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include<fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n,x,inc,i,in,sf,s,bests;
int main ()
{
    f>>n;
    s=0;
    bests=-1000001;
    for(i=1;i<=n;i++)
    {
        f>>x;
        if(s<0)
        {
            s=x;
            inc=i;
        }
        else
        s+=x;
        if(bests<s)
        {
            bests=s;
            in=inc;
            sf=i;
        }
    }
    g<<bests<<" "<<in<<" "<<sf;
    return 0;
}