Cod sursa(job #2925567)
| Utilizator | Data | 15 octombrie 2022 18:22:15 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
#include <deque>
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
deque <pair <int,int> >q;
int main()
{
int n,k,x,i;
long long s=0;
f>>n>>k;
for(i=1;i<=n;i++)
{
f>>x;
while(q.empty()==false && x<q.back().first)
{
q.pop_back();
}
q.push_back({x,i});
if(i>=k)
{
s=s+q.front().first;
if(i-k+1==q.front().second)
{
q.pop_front();
}
}
}
g<<s;
return 0;
}
