Cod sursa(job #632712)

Utilizator yamahaFMI Maria Stoica yamaha Data 12 noiembrie 2011 09:29:00
Problema Deque Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include<iostream>
#include<fstream>
#include<deque>
using namespace std;

int main ()
{
    ifstream f("deque.in");
    ofstream g("deque.out");
    deque<int> coada;
    long long n,k,i,x,s=0,j;
    f>>n>>k>>x;
    i=1;
    coada.push_back(x); j=i;
        
    while(f>>x)
    {
        i++;
        while(x<coada.back()) coada.pop_back();
        coada.push_back(x);
        if(coada.front()==x) j=i;
        if(j==i-k) coada.pop_front();
        if(i>=k){g<<coada.front()<<" ";s=s+coada.front();}
    }
    g<<endl<<s;
    
    f.close(); g.close();
    return 0;
}