Cod sursa(job #1048773)

Utilizator NitaMihaitavoidcube NitaMihaita Data 6 decembrie 2013 13:35:23
Problema Subsecventa de suma maxima Scor 65
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include<fstream>
#include<iostream>
#define numaru 2000001
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
long long s[numaru];
int main()
{
    int n,x,i,poz_max,poz_n_st,poz_max_st;
    f>>n;
    s[0]=-1;
    f>>s[1];
    poz_n_st=poz_max=poz_max_st=1;
    for(i=2;i<=n;++i)
    {
        f>>x;
        if(s[i-1]<=0){s[i]=x;poz_n_st=i;}
        else s[i]=s[i-1]+x;
        if(s[i]>s[poz_max]){poz_max=i;poz_max_st=poz_n_st;}
    }
    g<<s[poz_max]<<" "<<poz_max_st<<" "<<poz_max<<"\n";
    f.close();
    g.close();
    return 0;
}