Cod sursa(job #2801785)

Utilizator AndreiMLCChesauan Andrei AndreiMLC Data 16 noiembrie 2021 21:18:51
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <limits.h>
#define ll long long

using namespace std;

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

int main()
{
	int n, poz1, poz2, nr, poz, poz2max,poz1max;
	ll sum=0, sumante = INT_MIN;
	f >> n;
	for (int i = 1; i <= n; i++)
	{
		f >> nr;
		if (sum==0)
		{
			poz1 = nr;
		}
		sum += nr;
		poz = nr;
		if (sum > sumante)
		{
			poz1max = poz1;
			sumante = sum;
			poz2max = poz;
		}
		if (sum < 0)
		{
			poz1 = nr;
			poz2 = nr;
			sum = 0;
		}
	}
	g << sumante << " " << poz1max << " " << poz2max;
}