Cod sursa(job #2575205)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 6 martie 2020 12:04:58
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>

using namespace std;

ifstream fin("ssm.in");
ofstream fout("ssm.out");

const int NMAX = 6000005;
const int INF = 2e9;

int main()
{
	int n,x;
	int sc = 0,stc = 0,stmax=1,drmax=1, scmax = -INF;
	fin >> n;
	for (int i = 1; i <= n; i++)
	{
		fin >> x;
		if (sc + x >= x)
			sc += x;
		else
		{
			sc = x;
			stc = i;
		}
		if (sc > scmax)
		{
			scmax = sc;
			stmax = stc;
			drmax = i;
		}
	}
	fout << scmax << " " << stmax << " " << drmax << "\n";
	return 0;
}