Cod sursa(job #2324097)
Utilizator | Data | 20 ianuarie 2019 11:42:53 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int main()
{
int rez=0, p1=1, s=0, p2, n, x, p1rez=0, p2rez=0;
fin >> n;
for ( p2=1; p2<=n; p2++)
{
fin >> x;
s+=x;
if ( s<0 )
{
s=0;
p1=p2+1;
}
if ( s > rez )
{
rez=s;
p1rez=p1;
p2rez=p2;
}
}
fout << rez <<' '<< p1rez << ' ' << p2rez;
return 0;
}