Cod sursa(job #3220312)
Utilizator | Data | 3 aprilie 2024 09:29:21 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
using namespace std;
ifstream cin ("ssm.in");
ofstream cout ("ssm.out");
int main()
{
long long n,s,maxi=0,im,jm,i,aci=1;
cin>>n;
int v[n+1];
for(i=1;i<=n;i++)
cin>>v[i];
s=v[1];
maxi=v[1];
im=1;
jm=1;
for(i=2;i<=n;i++){
if(s<0){
aci=i;
s=0;
}
s+=v[i];
if(s>maxi){
maxi=s;
im=aci;
jm=i;
}
}
cout<<maxi<< ' ' <<im<< ' ' <<jm;
return 0;
}