Cod sursa(job #1935397)
Utilizator | Data | 22 martie 2017 12:08:39 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.83 kb |
#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;
}