Cod sursa(job #3287894)
| Utilizator | Data | 19 martie 2025 17:31:19 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("deque.in");
ofstream out("deque.out");
deque<pair<int,int>> q;
int n,k,i,x;
long long s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
in>>n>>k;
while(n--)
{
++i;
in>>x;
while(!q.empty() && q.front().second<=i-k)
q.pop_front();
while(!q.empty() && q.back().first>x)
q.pop_back();
q.push_back({x,i});
if(i>=k)
s+=q.front().first;
}
out<<s;
}
