Pagini recente » Cod sursa (job #464465) | Cod sursa (job #1729199) | Cod sursa (job #3131943) | Cod sursa (job #1727881) | Cod sursa (job #2720863)
#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;
}