Cod sursa(job #1843256)

Utilizator DobosDobos Paul Dobos Data 8 ianuarie 2017 15:13:08
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>
#define NMAX 500005
#define INF 1e9
using namespace std;

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

int V[NMAX];
deque < int > Q;

int main()
{
    ios :: sync_with_stdio(false);
    fin.tie(NULL);

    int n,k,sol = -INF,x,y;

    fin >> n >> k;

    for(int i = 1; i <= n; i++)
        fin >> V[i];

    for(int i = 1; i <= n; i++){
        while(!Q.empty() && V[Q.back()] > V[i])
            Q.pop_back();
        Q.push_back(i);
        if(Q.front() == i - k)
            Q.pop_front();
        if(V[Q.front()] > sol && i >= k){
            sol = V[Q.front()];
            x = Q.front();
            y = i;
        }

    }

    fout << x << " " << y << " " << sol;

    return 0;
}