Cod sursa(job #2956426)
Utilizator | Data | 19 decembrie 2022 15:35:56 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <iostream>
using namespace std;
int main()
{int n, sc=-1, smax=-100000, st=0, dr=0, stmax, drmax;
int x_i;
cin>>n;
for(int i=0;i<n;i++)
{cin>>x_i;
if(x_i>sc+x_i)
{
sc=x_i;
st=i;
}else{sc+=x_i;}
if(sc>smax)
{
smax=sc;
stmax=st;
drmax=i;
}}
cout<<smax<<" "<<stmax+1<<" "<<drmax+1;
return 0;
}