Cod sursa(job #2185737)
| Utilizator | Data | 24 martie 2018 20:16:11 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
//Enunt: http://www.infoarena.ro/problema/ssm
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int sp[6000000],N,cmax,st,dr;
int main()
{
in>>N;
int v[N];
for(int i=0;i<N;++i)
in>>v[i];
sp[0]=v[0];
int cmax=sp[0];
for(int i=1;i<N;++i)
{
sp[i]=max(sp[i-1]+v[i],v[i]);
if(sp[i]>cmax)
{
dr=i;
cmax=sp[i];
}
}
out<<cmax<<' ';
st=dr;
while(cmax>0)
{
cmax-=v[st];
--st;
}
out<<2+st<<' '<<1+dr;
return 0;
}
