Cod sursa(job #2324042)
Utilizator | Data | 20 ianuarie 2019 11:02:30 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f ("ssm.in");
ofstream g ("ssm.out");
int x,n,i,s[6000000],pmin,st,dr,mini,p2,smax,rez;
int main()
{
f>>n;
for(i=1;i<=n;i++){
f>>x;
s[i]=s[i-1]+x;
}
mini=0;
pmin=0;
for(p2=1;p2<=n;p2++){
smax=s[p2]-mini;
if(smax>rez){
rez=smax;
st=pmin;
dr=p2;
}
if(s[p2]<mini)
{
mini=s[p2];
pmin=p2;
}
}
g<<rez<<' '<<st+1<<' '<<dr;
return 0;
}