Cod sursa(job #2718193)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 8 martie 2021 16:05:21
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream cin("ssm.in");
ofstream cout("ssm.out");

const int INF = 2e9;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	int sc = 0, stc = 0, stmax = 1, drmax = 1, scmax = -INF;
	cin >> n;
	int x;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		if (sc + x >= x)
			sc += x;
		else
		{
			stc = i;
			sc = x;
		}
		if (sc > scmax)
		{
			scmax = sc;
			stmax = stc;
			drmax = i;
		}
	}
	cout << scmax << ' ' << stmax << ' ' << drmax << '\n';

	return 0;
}