Pagini recente » Cod sursa (job #2192263) | Cod sursa (job #2532844) | Cod sursa (job #1277382) | Cod sursa (job #2507328) | Cod sursa (job #2848069)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
#define INF -99999999
int main()
{
int n, x, i;
fin >> n;
int suma = 0, sum_max = 0, st = 1, dr = 0, st_rez = 1, dr_rez = 0, pozitive = 0;
int e_maxim = INF, poz_max;
for(i = 1; i <= n; i++)
{
fin >> x;
suma += x;
dr++;
if(suma < 0)
{
suma = 0;
st = i + 1;
}
if(suma > sum_max)
{
sum_max = suma;
dr = i;
st_rez = st;
dr_rez = dr;
}
if(x > 0)
pozitive++;
if(x > e_maxim)
{
e_maxim = x;
poz_max = i;
}
}
if(pozitive > 0)
fout << sum_max << " " << st_rez << " " << dr_rez;
else
fout << e_maxim << " " << poz_max << " " << poz_max;
return 0;
}