Cod sursa(job #3328761)
| Utilizator | Data | 10 decembrie 2025 09:58:14 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main()
{
int n,st,smax,drmax,stmax,x,i,s;
fin >> n;
fin >> x;
smax=s=x;
drmax=stmax=st=1;
for (i=2;i<=n;i++)
{
fin >> x;
if (s>=0)
{
s=s+x;
}
else{
st=i;
s=x;
}
if (s>smax)
{
smax=s;
drmax=i;
stmax=st;
}
}
fout << smax << ' ' << stmax << ' ' << drmax;
return 0;
}
