Pagini recente » Cod sursa (job #1528857) | Cod sursa (job #1076590) | Cod sursa (job #239766) | Cod sursa (job #2856990) | Cod sursa (job #471056)
Cod sursa(job #471056)
// 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;
int bst[2][2];
void read()
{
fscanf(f, "%d", &n);
}
void program()
{
int ret;
int max=-1000000000;
int maxi=0;
for (int i=1; i<=n; i++)
{
fscanf(f, "%d", &v);
if (bst[0][0]+v>bst[1][0])
{
bst[1][1]=bst[0][1];
bst[1][0]=bst[0][0]+v;
}
else
{
bst[1][1]=i;
bst[1][0]=v;
}
if (bst[1][0]>max)
{
max=bst[1][0];
maxi=i;
ret=bst[1][1];
}
bst[0][1]=bst[1][1];
bst[0][0]=bst[1][0];
bst[1][0]=0;
bst[1][1]=0;
}
fprintf(g, "%d ", max);
fprintf(g, "%d %d", ret, maxi);
}
int main()
{
read();
program();
return 0;
}