Cod sursa(job #1010894)

Utilizator Athena99Anghel Anca Athena99 Data 15 octombrie 2013 21:12:37
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <deque>

using namespace std;

ifstream fin("secventa.in");
ofstream fout("secventa.out");

const int nmax= 500000;

deque <int> d;

int v[nmax+1];

int main(  )
{
    int n, k, p= 0, sol= -(1<<30);
    fin>>n>>k;
    for ( int i= 1; i<=n; ++i ) {
        fin>>v[i];
        if ( i==k+d.front() ) {
            //printf("dfront %d\n",d.front());
            d.pop_front();
        }

        while ( d.empty()==0 && v[i]<v[d.back()] ) {
            //printf("dback %d\n",d.back());
            d.pop_back();
        }
        d.push_back(i);

        if ( k<=i && sol<v[d.front()] ) {
            p= i;
            sol= v[d.front()];
        }
    }

    fout<<p-k+1<<" "<<p<<" "<<sol<<"\n";

    return 0;
}