Pagini recente » Cod sursa (job #2650979) | Rating Somlea George Adrian (georgezidanic) | Cod sursa (job #188036) | Cod sursa (job #2287772) | Cod sursa (job #2866679)
#include <fstream>
#define maxN 6000000
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int x[maxN];
int n;
long long s=0;
int best[maxN];
int main()
{
int smax;
cin>>n;
for(int i=1;i<=n;i++)
cin>>x[i];
smax=best[1]=x[1];
int start,end,y;
for(int i=2;i<=n;i++)
{
if(best[i-1]+x[i]>x[i]) best[i]=best[i-1]+x[i];
else{
best[i]=x[i];
y=i;
}
if(smax<best[i] || (smax==best[i] && start>y)){
smax=best[i];
start=y;
end=i;
}
}
cout<<smax<<" "<<start<<" "<<end;
cin.close();
cout.close();
return 0;
}