Cod sursa(job #1638910)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 8 martie 2016 09:56:25
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include<iostream>
#include<fstream>

using namespace std;

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

int main ()
{
  int i, s, smax, N, st, dr, stmax, drmax, x;
  fin >> N;
  fin >> s;
  s = smax; st = stmax = 1; drmax = 1;
  if (s < 0) { s = 0; st = 2; }
  for (i=2; i<=N; i++)
  { 
     fin >> x;
     s += x;
     if (s > smax) { smax = s; stmax = st; drmax = i; }
     if (s < 0)    { s = 0; st = i+1; } 
  }
  fout << smax << " " << stmax << " " << drmax << "\n";
  fin.close();
  fout.close();
}