Pagini recente » Cod sursa (job #2162594) | Cod sursa (job #2586242) | Cod sursa (job #495221) | Cod sursa (job #2576289) | Cod sursa (job #2912615)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int a[6000001], bst[6000001];
int main()
{
int n;
in>>n;
for(int i=1; i<=n; i++)
in>>a[i];
bst[1]=a[1];
int maxim=bst[1];
int pos_max=1;
for(int i=2; i<=n; i++)
{
bst[i]=max(bst[i-1]+a[i], a[i]);
if(bst[i]>maxim)
{
maxim=bst[i];
pos_max=i;
}
}
int s=0,pos_st;
for(int i=pos_max; i>=1; i--)
{
s=s+a[i];
if(s==maxim)
{
pos_st=i;
break;
}
}
out<<maxim<<" "<<pos_st<<" "<<pos_max;
return 0;
}