Cod sursa(job #1991108)
| Utilizator | Data | 15 iunie 2017 10:36:01 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <iostream>
#include <fstream>
#include <deque>
#include <algorithm>
using namespace std;
deque <pair <int, int> > D;
int main()
{
int i;
int n, k;
long long s = 0;
pair <int, int> x;
ifstream in ("deque.in");
ofstream out ("deque.out");
in>>n>>k;
for(i=0;i<n;++i)
{
x.first = i;
in>>x.second;
if(!D.empty() && D.front().first <= i-k)
D.pop_front();
while (!D.empty() && D.back().second >=x.second)
{
D.pop_back();
}
D.push_back(x);
if(i>=k-1)
s+=D.front().second;
}
out<<s;
}
