Cod sursa(job #3320954)
| Utilizator | Data | 7 noiembrie 2025 18:40:29 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
struct z{
int val, poz;
};
deque <z> v;
int main() {
int n,k,x;
long long s=0;
f>>n>>k;
for(int i=1;i<=n;i++)
{
f>>x;
while(!v.empty()&&v.back().val>x)
v.pop_back();
v.push_back({x,i});
while(!v.empty()&&v.front().poz==i-k)
v.pop_front();
if(i>=k&&n>=i)
s+=v.front().val;
}
g<<s<<endl;
return 0;
}
