Cod sursa(job #2242823)
| Utilizator | Data | 19 septembrie 2018 16:52:16 | |
|---|---|---|---|
| Problema | Deque | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <bits/stdc++.h>
using namespace std;
int N,K,a[5000005];
deque <int> q;
int main()
{int i,s=0,b=0;
ifstream in("deque.in");
ofstream out("deque.out");
in>>N>>K;
for (i=1;i<=N;i++)
{
in>>a[i];
b=1;
while (b)
{
if (!q.empty())
{
if (a[i]<=a[q.back()])
q.pop_back();
else
b=0;
}
else
b=0;
}
q.push_back(i);
if (i-q.front()>=K)
q.pop_front();
if (i>=K)
s+=a[q.front()];
}
out<<s<<"\n";
}
