Pagini recente » Rezultatele filtrării | Diferente pentru stl intre reviziile 34 si 16 | Borderou de evaluare (job #23063) | Rezultatele filtrării | Cod sursa (job #1754964)
#include <fstream>
#include <deque>
using ll = long long;
std::deque <ll> q;
std::deque <ll> firstK;
int main()
{
ll n;
ll index;
ll k;
ll x;
ll sum;
std::ifstream mama("deque.in");
std::ofstream tata("deque.out");
mama >> n;
mama >> k;
for (index = 0; index < k; ++index)
{
mama >> x;
while ( (not q.empty()) and
(q.back() > x) )
{
q.pop_back();
}
q.push_back(x);
firstK.push_back(x);
}
sum = q.front();
for (; index < n; ++index)
{
mama >> x;
while ( (not q.empty()) and
(q.back() > x) )
{
q.pop_back();
}
q.push_back(x);
if (firstK.front() == q.front())
{
q.pop_front();
}
sum += q.front();
firstK.pop_front();
firstK.push_back(x);
}
tata << sum;
return 0;
}