Cod sursa(job #2657258)
| Utilizator | Data | 10 octombrie 2020 10:30:13 | |
|---|---|---|---|
| Problema | Deque | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
const int nmax=5000002;
typedef long long itneger;
ifstream fin("deque.in");
ofstream fout("deque.out");
int n, k;
deque<int> dsh;
itneger sum=0, a[nmax];
int main()
{
fin>>n>>k;
for(int i=0; i<n; i++)
{
fin>>a[i];
while(!dsh.empty() && a[i]<=a[dsh.back()]) dsh.pop_back();
dsh.push_back(i);
if(dsh.front()<i-k+1)
dsh.pop_front();
if(i>=k-1)
sum+=a[dsh.front()];
}
cout<<sum;
return 0;
}
