Cod sursa(job #2073887)
| Utilizator | Data | 23 noiembrie 2017 20:02:58 | |
|---|---|---|---|
| Problema | Deque | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include<fstream>
#include<set>
#define x first
#define y second
#include<deque>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
deque<pair<int,int> >d;
int n,k,a;
long long r;
int main()
{
fin>>n>>k;
for(int i=1;i<=n;i++)
{
fin>>a;
if(i!=1)
if(d.size())
while(d.back().x>=a)
d.pop_back();
d.push_back({a,i});
if(d.front().y<=i-k)
d.pop_front();
if(i>=k)
r+=d.front().x;
}
fout<<r;
}
