Cod sursa(job #2885746)

Utilizator Rares_StefanoiuRares Stefanoiu Rares_Stefanoiu Data 6 aprilie 2022 15:15:24
Problema Deque Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include<iostream>
#include<fstream>
using namespace std;
int main() {
	int x, i = 0, front = 0, back = -1, n, k, s = 0;
	ifstream f("deque.in.");
	ofstream g("deque.out");
	f >> n >> k;
	int* v = new int[n];
	int* d = new int[n];
	while (f >> x)
	{
		v[i] = x;
		while (front <= back and v[i] < v[d[back]])
			back--;
		back++;
		d[back] = i;
		if (i - k  >= d[front])
			front++;
		if (i >= k - 1)
			s = s + v[d[front]];
		i++;

	}
	cout << s;
}