Cod sursa(job #1042437)
| Utilizator | Data | 27 noiembrie 2013 00:17:56 | |
|---|---|---|---|
| Problema | Deque | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include<fstream>
#include<deque>
using namespace std;
int i,n,k,x,y,v[5000100];
long long int sum;
deque<int> d;
ifstream f("deque.in");
ofstream g("deque.out");
int main()
{
int s=0;
f>>n>>k;
for(i=1;i<=n;i++)
{
f>>v[i];
while(!d.empty()&&v[i]<=v[d.back()])
d.pop_back();
d.push_back(i);
if(d.front()==i-k)
d.pop_front();
if(i>=k)
s+=v[d.front()];
}
g<<s<<endl;
}
