Pagini recente » Istoria paginii runda/maxhit1/clasament | Istoria paginii runda/test_unu | Istoria paginii runda/de_ce_sa_ne_certam_iubi | Istoria paginii runda/simulare_oni1234 | Cod sursa (job #2887464)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
deque<int> numere;
deque<int> pozitii;
int nrElemente, k;
int main() {
int index, numar, suma = 0;
fin >> nrElemente >> k;
for (index = 0; index < nrElemente; index += 1) {
fin >> numar;
while (numere.empty() == 0 and numar <= numere.back()) {
numere.pop_back();
pozitii.pop_back();
}
numere.push_back(numar);
pozitii.push_back(index);
while (pozitii.empty() == 0 and pozitii.front() <= index - k) {
numere.pop_front();
pozitii.pop_front();
}
if (index >= k - 1) {
suma += numere.front();
}
}
fout << suma;
return 0;
}