Cod sursa(job #2801795)

Utilizator AndreiMLCChesauan Andrei AndreiMLC Data 16 noiembrie 2021 21:30:22
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 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=0, poz2max, poz1max;
	ll sum = 0, sumante = INT_MIN;
	f >> n;
	for (int i = 1; i <= n; i++)
	{
		f >> nr;
		poz++;
		if (sum == 0)
		{
			poz1 = poz;
		}
		sum += nr;
		if (sum > sumante)
		{
			poz1max = poz1;
			sumante = sum;
			poz2max = poz;
		}
		if (sum < 0)
		{
			poz1 = poz;
			sum = 0;
		}
	}
	g << sumante << " " << poz1max << " " << poz2max;
}