Cod sursa(job #2276091)
| Utilizator | Data | 4 noiembrie 2018 10:11:04 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
#include <deque>
#include <functional>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
#define ll long long
int n, k;
deque< pair<int, int> > q;
ll rez;
int main(){
int i, x;
fin >> n >> k;
for(i = 1; i <= n; i++){
if(i > k && q.front().second == i - k) q.pop_front();
fin >> x;
while(!q.empty() && x <= q.back().first) q.pop_back();
q.push_back(make_pair(x, i));
if(i >= k) rez += q.front().first;
}
fout << rez;
}
