Cod sursa(job #3165532)
Utilizator | Data | 6 noiembrie 2023 15:07:18 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#include <climits>
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int x,n,i,dr,st,st1;
long long s,Max=INT_MIN;
int main()
{
cin>>n>>x;
s=x,st=dr=st1=1;
for(i=2;i<=n;i++)
{
cin>>x;
if(s+x>x)
s+=x;
else
s=x,st1=i;
if(s>Max)
{
Max=s;
st=st1;
dr=i;
}
}
cout<<Max<<" "<<st<<" "<<dr;
return 0;
}