Pagini recente » Istoria paginii problema/prietene | Diferente pentru tema intre reviziile 32 si 31 | Istoria paginii utilizator/cavalerul16 | Istoria paginii utilizator/cornel92 | Cod sursa (job #2008051)
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int s, smax, x;
int main ()
{
int n, i, stmax, drmax, st, cnt;
fin >> n;
fin >> x;
s=smax=x;
stmax=drmax=1;
if (s<0)
{ s=0;
st=2;
cnt=0;
}
for (i=2; i<=n; i++)
{
fin >> x;
s += x;
cnt++;
if (s>smax)
{
smax=s;
stmax = st; drmax = st+cnt;
}
if (s<0)
{
s=0;
st=i+1;
cnt=0;
}
}
fout << smax << " " << stmax << " " << --drmax << "\n";
return 0;
}