Pagini recente » Cod sursa (job #961731) | Cod sursa (job #1595720) | Cod sursa (job #2162840) | Cod sursa (job #695725) | Cod sursa (job #2670053)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int x=-2000000005, n, ind1, ind2, s, i, smax, ind1max, ind2max, nrmax;
void versummax()
{
if(s>smax)
{
smax=s;
ind1max=ind1;
ind2max=ind2;
}
}
int main()
{
fin >> n;
ind1=1;
for(i=1;i<=n;i++)
{
fin >> x;
ind2=i;
if(x>nrmax)
{
nrmax=x;
}
if(s<0)
{
s=x;
versummax();
ind1=i;
}
else
{
s=s+x;
versummax();
}
}
if(nrmax<0)
fout << nrmax << " " << ind2max << " " << ind2max;
else
fout << smax << " " << ind1max << " " << ind2max;
return 0;
}