Cod sursa(job #778040)

Utilizator adascaluAlexandru Dascalu adascalu Data 13 august 2012 20:04:46
Problema Deque Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
using namespace std;
#include<fstream>
#include<deque>
#include<queue>
#define inFile "deque.in"
#define outFile "deque.out"
struct QComp
{
	bool operator()(const int&a,const int &b)const
	{
		return a>b;
	}
};
int main ()
{
	deque<int> v;
	priority_queue<int,vector<int>,QComp> heap;
	int n,k,x,s=0;
	ifstream f(inFile);
	f>>n>>k;
	for(int i=1;i<=k;i++)
	{
		f>>x;
		v.push_back(x);
		heap.push(x);
	}
	s+=heap.top();
	
	while(k!=n)
	{
		v.pop_front();
		heap.pop();
		f>>x;
		v.push_back(x);
		heap.push(x);
		k++,s+=heap.top();
	}
	
	f.close();
	ofstream g(outFile);
	g<<s;
	g.close();
	
	return 0;
}