Cod sursa(job #1539772)

Utilizator kassay_akosKassay Akos kassay_akos Data 1 decembrie 2015 16:11:32
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <iostream>
#include <fstream>
#include <string.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;
	int x, min = 1 << 30, minInd = 0, max = 0, maxInd = 0;
	for (int i = 1; i <= n; i++){
		scanf("%d", &x);
		a[i] = a[i - 1] + x;
		if (a[i] < min)			{ min = a[i]; minInd = i; };
		if (a[i] - min > max)	{ max = a[i] - min; maxInd = i; };
	}

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