Cod sursa(job #1372037)

Utilizator dianaorasanuDiana Orasanu dianaorasanu Data 4 martie 2015 11:03:11
Problema Subsecventa de suma maxima Scor 5
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <fstream>

#define IN "ssm.in"
#define OUT "ssm.out"

using namespace std;

ifstream fin(IN);
ofstream fout(OUT);

int i, n, a[101], x, y, bestS, best[101];
bool ok;

int main()
{
    fin >> n;
    for(i = 1; i <= n; ++i)
        fin >> a[i];
    bestS = a[1];
    for(i = 1; i <= n; ++i)
    {
        best[i] = a[i];
        if(best[i] < best[i-1] + a[i])
            {
                best[i] = best[i-1] + a[i];
                if(ok == false)
                {
                    x = i;
                    ok = true;
                    x++;
                }
            }
        if(bestS < best[i])
        {
            bestS = best[i];
            y = i;
        }
    }
    fout << bestS << ' ' << x << ' ' << y << '\n';

    return 0;
}