Pagini recente » Cod sursa (job #206746) | Cod sursa (job #893568) | Cod sursa (job #2774328) | Cod sursa (job #6446) | Cod sursa (job #778040)
Cod sursa(job #778040)
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;
}