Cod sursa(job #2174474)
Utilizator | Data | 16 martie 2018 12:13:36 | |
---|---|---|---|
Problema | Deque | Scor | 25 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("deque.in");
ofstream out ("deque.out");
int n,v[5000001],deq[5000001];
int main()
{
int n,k,i,s=1,d=0,suma=0;
in>>n >>k;
for (i=1;i<=n;++i)
{
in >> v[i];
if (s<=d && deq[s]==i-k)
{
s++;
}
while (s<=d && v[i]<=v[deq[d]])
{
d--;
}
deq[++d]=i;
if (i>= k)
suma+=v[deq[s]];
//cout << v[deq[s]] << ' ';}
}
out << suma;
return 0;
}
//ttps://infoarena.ro/problema/branzalllllllllaafsafsafa