Cod sursa(job #1254681)

Utilizator stefan_gheorgheGheorghe Stefan stefan_gheorghe Data 3 noiembrie 2014 09:59:17
Problema Subsecventa de suma maxima Scor 15
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n,i,j,s,x,y,smax,a[100];
int main()
{
    f>>n;
    smax=0;
    for(i=1;i<=n;i++)
    {
        f>>a[i];
    }
    for (i=1;i<=n;i++)
    {
        j=i;
        s=0;
        for (j=i;j<=n;j++)
        {
            s=s+a[j];
            if (s>smax)
            {
                smax=s;
                x=i;
                y=j;
            }
        }
    }
    g<<smax<<' '<<x<<' '<<y;
    return 0;
}