Cod sursa(job #1050971)
| Utilizator | Data | 9 decembrie 2013 15:36:28 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f ("deque.in");
ofstream g ("deque.out");
int n,k,i,a[5000100];
deque<int> d;
long long s;
int main()
{
f>>n>>k;
for(i=1;i<=n;i++)
{
f>>a[i];
while(d.empty()==0 && a[i]<=a[d.back()])
d.pop_back();
d.push_back(i);
if(d.front()==i-k)
d.pop_front();
if(i>=k)
s+=a[d.front()];
}
g<<s;
f.close();
g.close();
return 0;
}
