Cod sursa(job #1589080)

Utilizator VasileIzbavitorMartin Vasile VasileIzbavitor Data 3 februarie 2016 19:27:44
Problema Subsecventa de suma maxima Scor 25
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int v[10000];
int main()
{
    int s,maxi,dr,st,i,n,p;
    in>>n;
    s=0;
    maxi=-7134577;
     for(i=1;i<=n;i++)
        in>>v[i];
    i=1;
    maxi=v[i]; s=v[i]; dr=1; st=1; p=1;
    for(i=2;i<=n;i++)
    {
        s=s+v[i];
        if(s>maxi)
        {
            maxi=s;
            st=p;
            dr=i;
        }
        if(s<0)
        {
            s=0;
            p=i+1;
        }
    }
    out<<maxi<<" "<<st<<" "<<dr;
    in.close();
    out.close();
    return 0;
}