Cod sursa(job #2088476)
Utilizator | StanCatalin StanCatalin | Data | 15 decembrie 2017 12:16:25 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int INF=2000000;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int n,i,x,sc,smax,st,dr=0,k = 0,stmax;
in >> n;
sc = -1;
smax = -INF;
for (i=1;i<=n;i++)
{
in >> x;
if (sc < 0)
{
sc = x;
st = i;
}
else
{
sc += x;
}
if (sc > smax)
{
smax = sc;
stmax = st;
dr = i;
}
}
out << smax << " " << st << " " << dr;
return 0;
}