Cod sursa(job #1279100)

Utilizator RaduHHarhoi Radu RaduH Data 29 noiembrie 2014 19:31:28
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n,i,k,maxi=-2147000000,start,stop,s,x;
int main()
{
    fin>>n;
    fin>>x;
    s=x;
    for(i=1;i<n;i++)
    {
        fin>>x;
        if(s>=0)
        {
            s=s+x;
            if(s>maxi)
            {
                maxi=s;
                stop=i;
                start=k;
            }
        }
        else
        {
            k=i;
            s=x;
            if(s>maxi)
            {
                maxi=s;
                stop=i;
                start=k;
            }
        }
    }
    fout<<maxi<<" "<<start+1<<" "<<stop+1;
    fin.close();
    fout.close();
    return 0;
}