Cod sursa(job #2720863)
| Utilizator | Data | 11 martie 2021 12:51:08 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int n,x,bestSum,indice_dreapta,indice_stanga,indice;
int best[6000005];
int main()
{
in>>n;
bestSum=INT_MIN;
for(int i=1;i<=n;++i){
in>>x;
best[i]=x;
if(best[i]<best[i-1]+x)
best[i]=best[i-1]+x;
else
indice=i;
if(best[i]>bestSum){
bestSum=best[i];
indice_stanga=indice;
indice_dreapta=i;
}
}
out<<bestSum<<" "<<indice_stanga<<" "<<indice_dreapta;
return 0;
}
