Cod sursa(job #3283924)

Utilizator pituioanAndrei pituioan Data 10 martie 2025 18:26:24
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <fstream>
#include <algorithm>
using namespace std;
using ll = long long;

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

const int DIM = 6e6 + 5;
int a[DIM];
int n;

void Secv();

int main()
{
	fin >> n;

	for (int i = 1; i <= n; ++i)
		fin >> a[i];

	Secv();
}

void Secv()
{
	ll s{}, smax{};

	int i = 1, I = 1, J = 1;

	for (int j = 1; j <= n; ++j)
	{
		s += a[j];

		if (s >= 0)
		{
			if (s > smax)
			{
				smax = s;
				I = i, J = j;
			}
		}
		else
		{
			I = j + 1;
			s = 0;
		}
	}

	fout << smax << ' ' << I << ' ' << J;
}