Cod sursa(job #1724295)

Utilizator Vbs96Vitelaru Sebastian Vbs96 Data 2 iulie 2016 19:18:19
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int  n;
#define INT_MIN -9999999
#define INT_MAX 9999999
int main(){

	int i, x, s = 0 , s_max = INT_MIN, nr = 0, nr_max = INT_MIN,u_max=0;
	freopen("ssm.in", "r", stdin);
	freopen("ssm.out", "w", stdout);
	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%d", &x);
		if (s + x >= x){
			nr++;
			s += x;
		}
		else{
			s = x;
			nr = 1;
		}
		if (s > s_max){
			s_max = s;
			nr_max = nr;
			u_max = i;
		}
			
	}
	printf("%d %d %d", s_max, u_max-nr_max+1,u_max);
	return 0;
}