Cod sursa(job #2711667)

Utilizator AdrianSkStanciu Adrian AdrianSk Data 24 februarie 2021 16:09:21
Problema Secventa 2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");

int main() {
	int n, k;
	fin >> n >> k;
	
	int beginPoint, endPoint, sum = 0, maxSum = 0, x = 1, secv = 0;
	for(int i = 1; i <= n; ++i) {
		int nr;
		cin >> nr;
		
		if(sum < 0) {
			sum = nr;
			x = i;
			secv = 1;
		} else {
			sum += nr;
			beginPoint = x; endPoint = i - 1;
			++secv;
		}
		
		if(secv >= k) {
		   maxSum = max(sum, maxSum);
		   secv = 1;
		}
			
	}
	
	fout << beginPoint <<" "<< endPoint <<" "<< maxSum;
	
	return 0;
}