Cod sursa(job #3165535)

Utilizator Dia3141Costea Diana Stefania Dia3141 Data 6 noiembrie 2023 15:10:08
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>
#include <climits>
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
long long s,Max=INT_MIN,x,n,i,dr,st,st1;
int main()
{
    cin>>n>>x;
    Max=s=x,st=dr=st1=1;
    for(i=2;i<=n;i++)
    {
        cin>>x;
        if(s+x>x)
            s+=x;
        else
            s=x,st1=i;
        if(s>Max)
        {
            Max=s;
            st=st1;
            dr=i;
        }
    }
    cout<<Max<<" "<<st<<" "<<dr;
    return 0;
}