Cod sursa(job #967897)
| Utilizator | Data | 28 iunie 2013 18:33:41 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
int n,k,a[5000005],st=1,dr=0;
deque <int> q;
long long sol=0;
int main()
{ int i;
f>>n>>k;
for(i=1;i<=n;i++)
{ f>>a[i];
while(!q.empty() && a[i]<a[q.back()]) q.pop_back();
q.push_back(i);
while(q.front()<=i-k)
q.pop_front();
if (i>=k) sol+=a[q.front()];
}
g<<sol;
return 0;
}
