Cod sursa(job #1951346)
| Utilizator | Data | 3 aprilie 2017 16:08:42 | |
|---|---|---|---|
| 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,s=0;
vector <int> V;
deque <int> DQ;
ifstream f("deque.in");
ofstream g("deque.out");
int main()
{
f>>n>>k;
for(int i=1;i<=k;i++)
{
int x;
f>>x;
V.push_back(x);
while( !DQ.empty() && DQ.back()>=x ) DQ.pop_back();
DQ.push_back(x);
}
for(int i=k+1,st=0;i<=n;i++,st++)
{
s+=DQ.front();
int x;
f>>x;
V.push_back(x);
if(DQ.front()==V[st]) DQ.pop_front();
while( !DQ.empty() && DQ.back()>=x ) DQ.pop_back();
DQ.push_back(x);
}
s+=DQ.front();
g<<s;
}
