Cod sursa(job #1045781)
Utilizator | Data | 2 decembrie 2013 00:28:19 | |
---|---|---|---|
Problema | Deque | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include<iostream>
#include<fstream>
#include<deque>
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
deque<pair<long, long> >my_deq;
long n, k, i, x, s=0;
int main()
{
f>>n>>k;
f>>x;
my_deq.push_back(make_pair(x, 1));
for(i=2;i<=n;i++)
{
f>>x;
while((x<=my_deq.back().first)&& (int)(my_deq.size()!=0))
my_deq.pop_back();
my_deq.push_back(make_pair(x, i));
if(my_deq.front().second == i-k)
my_deq.pop_front();
if(i>=k)
s+=my_deq.front().first;
}
g<<s;
}