Cod sursa(job #2324044)

Utilizator SochuDarabaneanu Liviu Eugen Sochu Data 20 ianuarie 2019 11:03:38
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f ("ssm.in");
ofstream g ("ssm.out");
int x,n,i,s[6000000],pmin,st,dr,mini,p2,smax,rez;
int main()
{
    f>>n;
    for(i=1;i<=n;i++){
        f>>x;
        s[i]=s[i-1]+x;
    }
    rez=-200000000;
    mini=0;
    pmin=0;
    for(p2=1;p2<=n;p2++){
        smax=s[p2]-mini;
        if(smax>rez){
            rez=smax;
            st=pmin;
            dr=p2;
        }
        if(s[p2]<mini)
        {
            mini=s[p2];
            pmin=p2;
        }
    }
   g<<rez<<' '<<st+1<<' '<<dr;
    return 0;
}