Cod sursa(job #2828895)

Utilizator bumblebeeGeorge Bondar bumblebee Data 8 ianuarie 2022 09:06:13
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>
#include <climits>
using namespace std;

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

int main() {
	int n, best = 0, start_idx = 1, max_best = INT_MIN, value, max_start_idx = 1, max_end_idx = 1;
	fin >> n;
	for (int i = 1; i <= n; ++i) {
		fin >> value;
		if (value + best >= value) {
			best += value;
		} else if (value > best) {
			best = value;
			start_idx = i;
		}
		if (best > max_best) {
			max_best = best;
			max_start_idx = start_idx;
			max_end_idx = i;
		}
	}
	fout << max_best << " " << max_start_idx << " " << max_end_idx;
	return 0;
}