Cod sursa(job #2163011)
| Utilizator | Data | 12 martie 2018 16:26:36 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int x,n,i,st,dr,stmax,drmax;
long long smax,best[6000001];
int main()
{
fin>>n;
for (i=1;i<=n;i++)
{
fin>>x;
best[i]=x;
if (best[i]<best[i-1]+x) best[i]=best[i-1]+x;
if (best[i]>smax) {smax=best[i];drmax=i;stmax=st;}
if (best[i]==x) st=i;
}
fout<<smax<<" "<<stmax<<" "<<drmax<<'\n';
return 0;
}
