Cod sursa(job #2395529)
| Utilizator | Data | 2 aprilie 2019 17:38:32 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
#include <deque>
using namespace std;
const int NMAX=5000005;
ifstream fin("deque.in");
ofstream fout("deque.out");
deque < int > DQ;
long long V[NMAX],N,M,SUMA=0;
int main()
{
fin>>N>>M;
for (int i=1; i<=N; i++)
fin>>V[i];
for (int i=1; i<=N; i++)
{
while (!DQ.empty()&&V[i]<V[DQ.back()])
DQ.pop_back();
DQ.push_back(i);
if (DQ.front()==i-M)
DQ.pop_front();
if (i>=M)
SUMA+=V[DQ.front()];
}
fout<<SUMA<<"\n";
return 0;
}
