Cod sursa(job #2558619)
Utilizator | Data | 26 februarie 2020 18:07:22 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n,i,sc,smax,p,x,y,a[6000000];
int main()
{
f>>n;
for (i=1;i<=n;i++)
f>>a[i];
sc=smax=a[1];
p=1;
x=1;
y=1;
for (i=1;i<=n;i++)
{
if (sc<0)
{
sc=a[i];
p=i;
}
else
sc=sc+a[i];
if(sc>smax)
{
smax=sc;
x=p;
y=i;
}
}
g<<smax<<" "<<x<<" "<<y;
return 0;
}