Cod sursa(job #1951379)
| Utilizator | Data | 3 aprilie 2017 16:23:30 | |
|---|---|---|---|
| Problema | Deque | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.69 kb |
#include <fstream>
#include <algorithm>
#include <deque>
std::ifstream fin;
std::ofstream fout;
int main ()
{
int n;
int k;
fin.open("deque.in");
fin >> n >> k;
std::deque <int> Q;
const int Inf = 0x3f3f3f3f;
int minim {Inf};
int s(0);
while (n --)
{
int x;
fin >> x;
Q.push_back(x);
if (Q.size() == k)
{
minim = Inf;
for (auto y : Q)
if (y < minim)
minim = y;
s += minim;
Q.pop_front();
}
}
fin.close();
fout.open("deque.out");
fout << s;
fout.close();
return 0;
}
