Cod sursa(job #894007)

Utilizator harababurelPuscas Sergiu harababurel Data 26 februarie 2013 19:12:40
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <string.h>
#define nmax 6000005
using namespace std;

int v[nmax], curent, urmator, pre[nmax], sol, solpoz;

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

	int n, i, j, k;

	f>>n;
	for(i=0; i<n; i++) f>>v[i];

	urmator = -1;
	solpoz = n-1;
	for(i=n-1; i; i--) {
		if(v[i] > v[i] + urmator) {
			curent = v[i];
			pre[i] = i;
		}
		else {
			curent = v[i] + urmator;
			pre[i] = pre[i+1];
		}
		if(curent >= sol) sol = curent, solpoz = i;

		urmator = curent;
	}
	
	g<<sol<<" "<<solpoz+1<<" "<<pre[solpoz] + 1<<"\n";

	return 0;
}