Cod sursa(job #580191)

Utilizator mihaipopa12Popa Mihai mihaipopa12 Data 12 aprilie 2011 20:05:23
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include<fstream>

#define INF (1 << 30)

using namespace std;

ifstream f("ssm.in");
ofstream g("ssm.out");

int N,S,i,Smax,p,u;
int x,Pmax,Umax;

int main () {
	
	f >> N;
	
	S = Smax = -INF;
	
	for ( i = 1 ; i <= N ; ++i ){
		f >> x;
		if ( S + x >= x ){
			++u; S = S + x;
		}
		else{
			p = u = i; S = x;
		}
		if ( S > Smax ){
			Smax = S; Pmax = p; Umax = u;
		}
	}
	
	g << Smax << " " << Pmax << " " << Umax;
	
	f.close();
	g.close();
	
	return 0;
}