Cod sursa(job #1441212)

Utilizator SwagginInMyJaysaaaaaaaaaaaas SwagginInMyJays Data 23 mai 2015 22:18:26
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <deque>
#include <fstream>

using namespace std;

const int dmax = 500003;

deque < int > D;

int a[dmax];


int main(){
    ifstream fin ("secventa.in");
    ofstream fout ("secventa.out");
    int N, K, start, end, worst = -dmax;
    fin >> N >> K;
    for (int i = 1; i <= N; i++)
        fin >> a[i];
    for (int i = 1; i <= N; i++){
            while ( !D.empty() && a[i] <= a[D.back()]) D.pop_back();
            D.push_back(i);
            if (D.front() == i - K  ) D.pop_front();
            if (i >= K){
                    if (a[D.front()] > worst) worst = a[D.front()], start = i - K + 1 , end = i;;
            }
    }
    fout << start << " " << end << " " << worst;
    return 0;
}