Cod sursa(job #2433452)
| Utilizator | Data | 27 iunie 2019 14:42:10 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.65 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
deque <pair<ll,int>> coada;
int main()
{ int n,k;
f>>n>>k;
ll sum=0;
for(int i=1; i<=n; i++)
{ ll x;
f>>x;
bool ok=true;
while(!coada.empty() && ok)
{ ll ul=coada.back().first;
ok=false;
if(x<=ul)
{ ok=true;
coada.pop_back();
}
}
coada.push_back({x,i});
if(coada.front().second==i-k) coada.pop_front();
if(i>=k) sum+=coada.front().first;
}
g<<sum;
return 0;
}
