Cod sursa(job #677247)

Utilizator nautilusCohal Alexandru nautilus Data 9 februarie 2012 22:34:03
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include<fstream>
using namespace std;
#define NMAX 6000010

int n;
int ssm,pozissm,pozfssm;

void read_solve()
{
 int i,x;
 int best,pozibest,pozfbest;
 ifstream fin("ssm.in");
 fin>>n;
 for (i=1; i<=n; ++i)
	{
	 fin>>x;
	 if (i == 1)
		{
		 best = ssm = x; 
		 pozibest = pozfbest = pozissm = pozfssm = 1;
		} else
		{
		 if (best + x >= x)
			{
			 best += x;
			 pozfbest++;
			}else
			{
			 best = x;
			 pozibest = i;
			 pozfbest = i;
			}
		 if (best > ssm)
			{
			 ssm = best;
			 pozissm = pozibest;
			 pozfssm = pozfbest;
			}
		}
	}
 fin.close();
}

void write()
{
 ofstream fout("ssm.out");
 fout<<ssm<<" "<<pozissm<<" "<<pozfssm<<'\n';
 fout.close();
}

int main()
{
 read_solve();
 write();
 return 0;
}