Cod sursa(job #2815799)

Utilizator george_buzasGeorge Buzas george_buzas Data 10 decembrie 2021 12:52:28
Problema Secventa 2 Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <vector>
#include <climits>
using namespace std;

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

int partial_sum[50001], max_sum = INT_MIN;

int main() {
	int n, k, current_element;
	fin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		fin >> current_element;
		partial_sum[i] = partial_sum[i - 1] + current_element;
	}
	int start_pos, end_pos;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + k - 1; j <= n; ++j) {
			if (partial_sum[j] - partial_sum[i - 1] > max_sum) {
				max_sum = partial_sum[j] - partial_sum[i - 1];
				start_pos = i;
				end_pos = j;
			}
		}
	}
	fout << start_pos << ' ' << end_pos << ' ' << max_sum;
	return 0;
}