Pagini recente » Cod sursa (job #1892875) | Cod sursa (job #1984675) | Cod sursa (job #1515995) | Cod sursa (job #907466) | Cod sursa (job #1935397)
#include <fstream>
using namespace std;
long long n,i,t,x,OK,a,Max=-200000000,b,Max2=-200000000,c;
int main()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f>>n;
f>>x;
t=x;
a=1;OK=1;
if(x>Max2)
{
Max2=x;
c=1;
}
for(i=2;i<=n;i=i+1)
{
f>>x;
if(x>Max2)
{
Max2=x;
c=i;
}
if(t+x>0)
{
t=t+x;
if(OK==0)
{
a=i;
OK=1;
}
if(t>Max)
{
Max=t;
b=i;
}
}
else
{
t=0;
OK=0;
}
}
if(Max2>Max)
g<<Max2<<' '<<c<<' '<<c;
else
g<<Max<<' '<<a<<' '<<b;
return 0;
}