Cod sursa(job #540745)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 24 februarie 2011 12:45:44
Problema Deque Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream.h>
long long s;
int j, n, k, m, a[5000001], w, i;
int main()
{
	ifstream f("deque.in");
	ofstream g("deque.out");
	f >> n >> k;
	s = 0;
	for (i = 1;i <= n;i++) f >> a[i];
	for (w = 1;w <= n - k + 1;w++)
	{
		m = a[w];
		for (j = w + 1;j <= w + k - 1;j++) if (a[j] < m) m = a[j];
		s = s + m;
	}
	g << s << '\n';
	g.close();
	return 0;
}