Cod sursa(job #1208203)

Utilizator tudi98Cozma Tudor tudi98 Data 15 iulie 2014 01:25:48
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <deque>
using namespace std;

struct P{int x,y;};
deque<P> D;

int main(){

    ifstream f("secventa.in");
    ofstream g("secventa.out");

    int n,k,x,I,J;
    int Val=-30001;
    f >> n >> k;
    for(int i=1;i<=n;i++){
        f >> x;
        while(!D.empty() && x<D.back().x) D.pop_back();
        P a;
        a.x=x;
        a.y=i;
        D.push_back(a);
        if(i-D.front().y+1>k) D.pop_front();
        if(i>=k && D.front().x>Val){
            Val=D.front().x;
            J=i;
            I=i-k+1;
        }
    }
    g << I << " " << J << " " << Val << "\n";
}