Pagini recente » Istoria paginii utilizator/mihailtifrea | Diferente pentru runda/iuiui intre reviziile 2 si 1 | Profil AndreiCelMort | Profil dianavasilescu | 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;
}