Cod sursa(job #1928463)
Utilizator | Data | 16 martie 2017 12:36:06 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
using namespace std;
int n,i,t,x,OK,a,Max=-200000000,b;
int main()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f>>n;
f>>x;
t=x;
for(i=2;i<=n;i=i+1)
{
f>>x;
if(t+x>0)
{
t=t+x;
if(OK==0)
{
a=i;
OK=1;
}
if(t>Max)
{
Max=t;
b=i;
}
}
else
{
t=x;
OK=0;
}
}
g<<Max<<' '<<a-1<<' '<<b;
return 0;
}