Cod sursa(job #2979218)

Utilizator LucaxdTomsa Luca Lucaxd Data 14 februarie 2023 20:34:58
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
#include <climits>
#include <stdlib.h>
#include <cmath>
typedef long long ll;
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
const int nmax = 6e6;
int n, v[nmax + 1], st, dr, istart, s = -1, maxi = INT_MIN;
int main()
{
	fin >> n;
	for (int i = 1; i <= n; i++)
		fin >> v[i];
	for (int i = 1; i <= n; i++)
	{
		if (s < 0)
			s = 0, istart = i;
		s += v[i];
		if (s > maxi)
			maxi = s, st = istart, dr = i;
	}
	fout << maxi << ' ' << st << ' ' << dr;
	return 0;
}