Cod sursa(job #1659977)

Utilizator andichsiChesoi Andi andichsi Data 22 martie 2016 18:53:19
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    int
        v[100],
        s,
        BIGGEST_S = -2000000000,
        START_OF_V,
        END_OF_V,
        n;
    ifstream f("ssm.in");
    ofstream o("ssm.out");
    f>>n;
    for(int i = 0; i < n; i++)
        f>>v[i];
    for(int i = 0; i < n; i++)
    {
        s = 0;
        for(int j = i; j < n; j++)
        {
            s += v[j];
            if(s > BIGGEST_S)
            {
                BIGGEST_S = s;
                START_OF_V = i;
                END_OF_V = j;
            }
        }
    }
    o<<BIGGEST_S << " "<< START_OF_V<< " "<< END_OF_V;
}