Cod sursa(job #1899079)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 2 martie 2017 15:17:19
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin  ("ssm.in");
ofstream fout ("ssm.out");

int main ()
{
 int x, i, N, st, dr, stmax, drmax;
 long long int s, smax;
 fin >> N;
 fin >> x;

 s=x; smax=s;
 if (s<0)
 s=0;
 stmax=drmax=1;

 for (i=2; i<=N; i++)
 {
   fin >> x;
   s=s+x;

   if (s>smax)
   { smax=s;
     drmax=i;
     stmax=st;
   }
   if (s<0)
     { s=0;
       st=i+1;
     }
 }

 fout << smax << " " << stmax << " " << drmax << "\n";
 return 0;
}