Cod sursa(job #2213886)

Utilizator pacheprotopopescuPake Protopopescu pacheprotopopescu Data 17 iunie 2018 20:39:23
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n,v[6000001],x,s,stg=1,dr=1,mx,k;
int main()
{
    f>>n>>x;
    s=x;mx=x;
    for(int i=2;i<=n;i++)
    {
        f>>x;
        if(s<0)
        {
            s=x;
            k=i;dr=i;
        }
         else s=s+x;
        if(mx<s)
                 {
                     mx=s;
                     stg=k;
                     dr=i;
                 }
              }
    g<<mx<<" "<<stg<<" "<<dr;
}