Pagini recente » Diferente pentru problema/fnaf intre reviziile 9 si 8 | Monitorul de evaluare | Cod sursa (job #944574) | Profil BonnY | Cod sursa (job #2600468)
#include <fstream>
#include <deque>
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
deque<pair<int,int>>q;
int n,k;
long long suma=0;
int main()
{
f>>n>>k;
for(int i=1; i<=n; i++)
{
int x;
f>>x;
while(q.size() and q.front().second+k<=i)
q.pop_front();
while(q.size() and q.back().first>x)
{
q.pop_back();
}
q.push_back({x,i});
if(i>=k)
suma+=q.front().first;
}
g<<suma;
return 0;
}