Cod sursa(job #2536097)
| Utilizator | Data | 1 februarie 2020 15:02:31 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 85 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.77 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, i;
int x;
int in, sf, lg;
long long smax, s;
int main()
{
fin>>n;
for(i = 1;i <= n;i++)
{
fin>>x;
lg++;
if(x > 0)
{
s += x;
}
else
{
if(s > smax)
{
smax = s;
sf = i - 1;
in = i - lg + 1;
}
if(s + x < 0)
{
s = 0;
lg = 0;
}
else s += x;
}
}
if(s > smax)
{
smax = s;
sf = i - 1;
in = i - lg + 1;
}
fout<<smax<<" "<<in<<" "<<sf;
return 0;
}
