Cod sursa(job #885908)

Utilizator Andrei121Andrei Ghigheci Andrei121 Data 22 februarie 2013 15:04:19
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;
ifstream in("ssm.in");
ofstream out ("ssm.out");
int main()
{
    int n , i ,v ,sc=0,scmax=0,pmax, p = 1, umax, max=-9999999 ,poz;
    in >> n;
    for(i=1;i<=n;i++){
        in >> v;
        if(v>max)
        {
            max=v;
            poz=i;
        }
        if(sc<0)
        {
            sc=0;
            p = i;
        }
        sc+=v;
        if(sc>scmax)
        {
            pmax = p;
            umax = i;
            scmax=sc;
        }

    }
    if(scmax==0)
    {
        out << max << ' ' << poz << ' ' << poz;
    }
    else
        out << scmax << ' ' << pmax << ' ' << umax;
    return 0;
}