Pagini recente » Cod sursa (job #2655682) | Cod sursa (job #3138746) | Cod sursa (job #1869099) | Cod sursa (job #693985) | Cod sursa (job #471053)
Cod sursa(job #471053)
// 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);
}
int maxim(int x, int y)
{
if (x>y) return x;
return y;
}
void program()
{
int ret;
int max=0;
int maxi=0;
for (int i=1; i<=n; i++)
{
fscanf(f, "%d", &v);
bst[1][0]=maxim(bst[0][0]+v, v);
if (bst[1][0]==bst[0][0]+v)
bst[1][1]=bst[0][1];
else
bst[1][1]=i;
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;
}