Cod sursa(job #2240605)

Utilizator ciutanpCiuta Andrei Calin ciutanp Data 13 septembrie 2018 19:42:10
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n,ras1,ras2,x,y;
long long s,a,sm=-int(2e9);
int main()
{
    f>>n;
    for(int i=1;i<=n;++i)
    {
        f>>a;
        if(s<0)
            s=a,x=i;
        else
            s+=a,y=i;
        if(s>sm)
            sm=s,ras1=x,ras2=i;
    }
    g<<sm<<' '<<ras1<<' '<<ras2;
}