Cod sursa(job #2162982)
| Utilizator | Data | 12 martie 2018 16:19:10 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int smax,x,n,i,st,dr,stmax,drmax,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;
else st=i;
if (best[i]>smax) {smax=best[i];drmax=i;stmax=st;}
}
fout<<smax<<" "<<stmax<<" "<<drmax<<'\n';
return 0;
}
