Cod sursa(job #3194468)

Utilizator Programmer0101Tudor Oancea Programmer0101 Data 18 ianuarie 2024 09:32:03
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream> 
#include <climits>
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int main() {
	int smax = INT_MIN, s = 0;
	int n;
	cin >> n;
	int x=1, y=1, xmax=1, ymax=1;

	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		s += a;
		if (s < 0) {
			s = 0;
			x = i+1;
		}
		if (s > smax) {
			smax = s;
			xmax = x;
			ymax = i;
		}
		
		
	}
	if (smax == 0)
		cout << 0 << ' ' << 1 << ' ' << 2;
	else
	cout << smax << ' ' << xmax << ' ' << ymax;
}