Pagini recente » Cod sursa (job #2837308) | Cod sursa (job #1496584) | Cod sursa (job #2101434) | Cod sursa (job #2801805) | Cod sursa (job #1075857)
#include <cstdio>
using namespace std;
int a[6000000],best[6000000],bestsum,i,n,I,m;
int main ()
{
freopen ("ssm.in","r",stdin);
freopen ("ssm.out","w",stdout);
scanf ("%d", &n);
for (i=1; i<=n; i++)
scanf ("%d", &a[i]);
bestsum = -2000000 ;
for (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];
I=i;
}
}
m=I;
printf("%d ", bestsum);
while (bestsum!=0)
{
bestsum-=a[I];
I--;
}
while (a[I]==0) I--;
printf ("%d %d", I+1, m);
return 0;
}