Cod sursa(job #1371850)

Utilizator BFlorin93Balint Florin-Lorand BFlorin93 Data 4 martie 2015 09:30:19
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
// subsecventa.cpp : Defines the entry point for the console application.
//

#include "iostream"
#include "algorithm"
#include "fstream"

using namespace std;

ifstream inputFile;
ofstream outFile;


void ssm(int n)
{
	int newInt;
	inputFile >> newInt;

	int *best = new int[n];
	int *maxCompute = new int[n];

	best[0] = newInt;
	maxCompute[0] = 0;

	for (int i = 1; i < n; i++)
	{
		inputFile >> newInt;
		if (newInt > best[i - 1] + newInt)
		{
			best[i] = newInt;
			maxCompute[i] = 0;
		}
		else
		{
			best[i] = best[i - 1] + newInt;
			maxCompute[i] = 1;
		}
	}

	int max = best[0];
	int end = 0;
	int start = 0;
	for (int i = 0; i < n; i++)
		if (max < best[i])
		{
			end = i;
			max = best[i];
		}


	outFile << max << " ";
	start = end;

	while (maxCompute[start])
	{
		start--;
	}

	outFile << start + 1 << " " << end + 1;
}

int main()
{
	inputFile.open("ssm.in", ios::in);
	outFile.open("ssm.out", ios::out);

	int n;
	inputFile >> n;
	
	ssm(n);
	

	inputFile.close();
	outFile.close();

	return 0;
}