Mai intai trebuie sa te autentifici.

Cod sursa(job #3293614)

Utilizator mihaigeorgescuGeorgescu Mihai mihaigeorgescu Data 12 aprilie 2025 09:38:12
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>
#define int long long
using namespace std;
ifstream fcin("ssm.in");
ofstream fout("ssm.out");
int n,x,s,maxx=-(1LL<<40),st, ind1,ind2;
signed main()
{
    fcin>>n;
    st=1;
    for(int i=1; i<=n; i++)
    {
        fcin>>x;
        s+=x;
        if(s>maxx)
        {
            maxx=s;
            ind1=st;
            ind2=i;
        }
        if(s<0) st=i+1, s=0;
    }
    fout<<maxx<<" "<<ind1<<" "<<ind2;
    return 0;
}