Cod sursa(job #1496619)
| Utilizator | Data | 5 octombrie 2015 11:50:40 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
deque < pair<int, int > > q;
int n, k;
long long rez;
int main()
{
fin>>n>>k;
for(int i=1; i<=n; ++i)
{
int x;
fin>>x;
while(!q.empty() and x < q.back().second)
q.pop_back();
q.push_back({i, x});
if(q.front().first < i - k + 1)
q.pop_front();
if(i >= k)
rez = rez + q.front().second;
}
fout<<rez;
return 0;
}
