Cod sursa(job #795841)

Utilizator toranagahVlad Badelita toranagah Data 9 octombrie 2012 19:01:11
Problema Subsecventa de suma maxima Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>
using namespace std;

ifstream fin("ssm.in");
ofstream fout("ssm.out");

int N;

int main(int argc, char const *argv[])
{
    fin >> N;
    int max = 0, mis = 0, mie = 0;
    int best = 0;
    int x;
    int is, ie;
    for (int i = 0; i < N; ++i) {
        fin >> x;
        if (best + x > x) {
            best += x;
            ie = i + 1;
        } else {
            best = x;
            is = ie = i + 1;
        }
        if (best > max) {
            max = best;
            mis = is;
            mie = ie;
        }  
    }
    fout << max << ' ' << mis << ' ' << mie;
    return 0;
}