Cod sursa(job #2863291)

Utilizator QwertyDvorakQwerty Dvorak QwertyDvorak Data 6 martie 2022 15:59:48
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define dbg(x) cout << #x <<": " << x << "\n";
using ll = long long;

const string myf = "ssm";
ifstream fin(myf + ".in");
ofstream fout(myf + ".out");

int n;
ll x;
int main() {

	ll s = 0, mxs = -2e9, dim = 0;
	ll in, fn;
	fin >> n;
	in = fn = -1;
	for (int i = 1; i <= n; ++i) {
		fin >> x;
		s += x;
		dim++;
		if (s >= mxs) {
			mxs = s;
			fn = i;
			in = fn - dim + 1;
		}
		if (s < 0) {
			s = 0;
			dim = 0;
		}
	}
	fout << mxs << " " << in << " " << fn;
	fin.close();
	fout.close();
	return 0;
}