Pagini recente » Cod sursa (job #2444389) | Cod sursa (job #3196123) | Cod sursa (job #933191) | Cod sursa (job #1947921) | Cod sursa (job #470885)
Cod sursa(job #470885)
// SubsecventaDeSumaMaxima.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "stdio.h"
FILE *f=fopen("ssm.in", "r");
FILE *g=fopen("ssm.out", "w");
int n, v[6000001];
int bst[6000001];
void read()
{
fscanf(f, "%d", &n);
for (int i=1; i<=n; i++)
fscanf(f, "%d", &v[i]);
}
int maxim(int x, int y)
{
if (x>y) return x;
return y;
}
void program()
{
int max=0;
int maxi=0;
for (int i=1; i<=n; i++)
{
bst[i]=maxim(bst[i-1]+v[i], v[i]);
if (bst[i]>max)
{
max=bst[i];
maxi=i;
}
}
fprintf(g, "%d ", max);
int j=maxi;
while (max>0)
{
max-=v[j];
j--;
}
fprintf(g, "%d %d", j+1, maxi);
}
int main()
{
read();
program();
return 0;
}