Pagini recente » Cod sursa (job #376) | Cod sursa (job #1780589) | Cod sursa (job #2401871) | Cod sursa (job #1443968) | Cod sursa (job #1155935)
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[6000000],best[6000000],x;
int main()
{
freopen ("ssm.in","r",stdin);
freopen ("ssm.out","w",stdout);
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int bestSum = a[1];
for (int i = 1; i <= n; ++ i)
{
best[i] = a[i];
if (best[i] < best[i-1] + a[i])
best[i] = best[i-1] + a[i];
if (bestSum < best[i])
bestSum = best[i];
}
for(int i=0;i<n;i++)
if(best[i]==bestSum)
x=i;
int i,s=0;
for(i=x;s!=bestSum;i--)
s+=a[i];
printf("%d %d %d",bestSum,i+2,x+1);
return 0;
}