Cod sursa(job #581505)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 14 aprilie 2011 11:56:41
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include<fstream>
#include<iostream>
using namespace std;
int s,maxx=(1<<31)-1;
int ind,b,e,N;
inline void citire()
{
	ifstream in("ssm.in");
	ofstream out("ssm.out");
	in>>N;
	ind=1;
	int x;
	maxx*=-1;
	for (int i=1; i<=N; ++i)
	{
		in>>x;
		if (s<0)
		{
			s=x;
			ind=i;
		}
		else
			s+=x;
		if (maxx<s)
		{
			maxx=s;
			b=ind;
			e=i;
		}
	}
	out << maxx <<" "<< b <<" "<<e;
	in.close();
	out.close();
}
int main()
{
	citire();
	return 0;
}