Cod sursa(job #1254678)

Utilizator stefan_gheorgheGheorghe Stefan stefan_gheorghe Data 3 noiembrie 2014 09:57:23
Problema Subsecventa de suma maxima Scor 15
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 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;
        while (j<=n)
        {
            s=s+a[j];
            if (s>smax)
            {
                smax=s;
                x=i;
                y=j;
                j++;
            }
            else
            {
                j++;
            }

        }
    }
    g<<smax<<' '<<x<<' '<<y;
    return 0;
}