Cod sursa(job #2432404)

Utilizator StefanSanStanescu Stefan StefanSan Data 23 iunie 2019 15:59:30
Problema Secventa 2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <algorithm>
#include <cmath>
#include <fstream>

#define ll long long int
#define MAX 50001

using namespace std;

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

ll a[MAX], n, k, x, maxim = INT_MIN, st, d, s = INT_MAX, p;

int main() {
	in >> n >> k;
	a[0] = 0;
	for (int i = 1; i <= n; i++) in >> x, a[i] = a[i - 1] + x;
	for (int i = k; i <= n; i++) {
		if (a[i - k] < s) s = a[i - k], p = i - k + 1;
		if (a[i] - s > maxim)maxim = a[i] - s, st = p, d = i;
	}
	out << st << " " << d << " " << maxim;
	
}