Cod sursa(job #2331015)
| Utilizator | Data | 29 ianuarie 2019 09:01:25 | |
|---|---|---|---|
| Problema | Deque | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("deque.in");
ofstream out("deque.out");
deque<int> x;
int n,k,a[5000008],suma=0,c;
int main()
{
in>>n>>k;
for(int i =1;i<=n;i++)
in>>a[i];
c=k;
k=1-k;
for(int i =1;i<=n;i++)
{
while(!x.empty()&&a[i]<=a[x.back()])
x.pop_back();
while(x.empty()==false && x.front()<=k)
x.pop_front();
x.push_back(i);
k++;
if(i>=c)
{
out<<a[x.front()]<<"\n";suma+=a[x.front()];}
}
out<<suma;
return 0;
}
