Pagini recente » Cod sursa (job #1170835) | Cod sursa (job #710734) | Cod sursa (job #2981018) | Cod sursa (job #2273776) | Cod sursa (job #2912617)
#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=0;
for(int i=pos_max; i>=1; i--)
{
s=s+a[i];
if(s==maxim)
{
pos_st=i;
break;
}
}
while(pos_st-1>=1 && s+a[pos_st-1]==maxim)
{
pos_st--;
}
out<<maxim<<" "<<pos_st<<" "<<pos_max;
return 0;
}