Cod sursa(job #1023050)

Utilizator ibicecIT Zilla ibicec Data 6 noiembrie 2013 12:58:58
Problema Subsecventa de suma maxima Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <fstream>
#include <cassert>

using namespace std;

int main() {
	int n;
	ifstream inp("ssm.in");
	ofstream out("ssm.out");
	
	inp >> n;
	
	int *a = new int[n];
	
	for (int i=0; i<n; i++) {
		inp >> a[i];
	}
	
	int max_sum = a[0], st = 0, en = 0;

	for (int i=0; i<n; i++) {
		for (int j=i; j<n; j++) {
			int sum = 0;
			for (int k=i; k<=j; k++) {
				sum += a[k];
			}
			if ( sum > max_sum ) {
				max_sum = sum;
				st = i;
				en = j;
			}
		}
	}
	
	out << max_sum << " " << st+1 << " " << en+1 << endl;
}