Cod sursa(job #856323)

Utilizator Theorytheo .c Theory Data 16 ianuarie 2013 11:50:06
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream>
#include<vector>
#include<queue>
using namespace std;

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


#define NMAX 500003

int a[NMAX];
int N; int K;
deque <int> q;
int last , baza = 0;

void Read () {

    fin >> N >> K;
    for(int i = 1; i <= N; i++)
        fin >> a[i];

}

void Solve() {

    for(int i = 1; i <= K; i++){
        if(!q.empty() && a[i] <= a[q.back()]) q.pop_back();
        q.push_back(i);
    }

    baza = a[q.front()];
    last = K ;

    for(int i = K + 1 ; i <= N; i++){
        if(q.front() == i - K) q.pop_front();

        if(!q.empty() && a[i] <= a[q.back()]) q.pop_back();
        q.push_back(i);

        if(a[q.front()] > baza){
            baza = a[q.front()];
            last = i;
        }
    }

}


void Print(){

    fout << last - K + 1<<" "<<last << " "<< baza<<'\n';
}


int main() {

    Read();

    Solve();

    Print();

    return 0;
}