Cod sursa(job #1010278)

Utilizator Mitsa3Neamt Mihai Mitsa3 Data 14 octombrie 2013 17:46:02
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int n;
int nr, i;
int st, poz, sol, SMax, dr;
int main()
{
    fin >> n;
    sol = -0x3f3f3f3f;
    for (i=1;i<=n;++i)
    {

     fin >> nr;
     if (SMax < 0)
     {
         SMax = nr;
         poz = i;
     }
     else
         SMax += nr;
     if (SMax > sol)
     {
         sol = SMax;
         st = poz;
         dr = i;
     }
 }
    fout << sol << " ";
    fout << st << " " << dr << "\n";

    return 0;
}