Cod sursa(job #1539781)

Utilizator kassay_akosKassay Akos kassay_akos Data 1 decembrie 2015 16:23:53
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <string.h>
#include <limits.h>
//#include <vector>
//#include <queue>
//#include <algorithm>

using namespace std;
const int nmax = 6000003;
int n;
int a[nmax];

int main(){
	freopen("ssm.in", "r", stdin);
	freopen("ssm.out", "w", stdout);
	scanf("%d", &n);

	a[0] = 0;
	for (int x,i = 1; i <= n; i++){
		scanf("%d", &x);
		a[i] = a[i - 1] + x;
	}

	int min = a[1], minInd = 1, max = a[1], maxInd = 1;
	for (int i = 1; i <= n; i++){
		if (a[i] < min)			{ min = a[i]; minInd = i+1; };
		if (a[i] - min > max)	{ max = a[i] - min; maxInd = i; };
	}

	printf("%d %d %d", max, minInd, maxInd);
	fclose(stdin);
	fclose(stdout);
	return 0;
}