Cod sursa(job #2035683)

Utilizator gavra_bogdanBogdan Gavra gavra_bogdan Data 9 octombrie 2017 19:10:50
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;
int main()
{
    ifstream cin("ssm.in");
    ofstream cout("ssm.out");
    int n,s=0,c,i=1,j=1,posi,posj,mx=INT_MIN;
    cin>>n;
    for(i=1;i<=n;i++)
        {
            cin>>c;
            s+=c;
        if(s>mx)
            {
            mx=s;
            posi=i;
            posj=j;
            }
        if(s<0)
        {
            j=i+1;
            s=0;
        }
        }
    cout<<mx<<" "<<posj<<" "<<posi;
    return 0;
}