Cod sursa(job #2906385)

Utilizator alexdvResiga Alexandru alexdv Data 25 mai 2022 22:43:03
Problema Secventa 2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;

int n, z, v[1001], actS = 0, maxS = -1, pos = 0, first, last;

int main() {
    ifstream fin ("secv2.in");
    ofstream fout ("secv2.out");
	cin >> n >> z;
	for (int i = 1; i <= n; ++i) {
		cin >> v[i];
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; ++j) {
			for (int k = i; k <= j; ++k) {
				actS = actS + v[k];
				++pos;
			}
			if (actS > maxS && pos >= z) {
				maxS = actS;
				first = i, last = j;
			}
			actS = 0;
			pos = 0;
		}
	}
	cout << first << ' ' << last << ' ' << maxS << '\n';
	return 0;
}