Mai intai trebuie sa te autentifici.
Cod sursa(job #2158274)
Utilizator | Data | 10 martie 2018 11:46:31 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
#include <limits.h>
using namespace std;
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, i, x, s=0, sMax=INT_MIN, start, stop, aux;
fin >> n;
for(int i=0; i<n; i++)
{
fin >> x;
s+=x;
if(s>sMax)
{
sMax=s;
start=aux;
stop=i;
}
if(s<0)
{
aux=i+1;
s=0;
}
}
fout << sMax << " " << start+1 << " " << stop+1;
return 0;
}