Cod sursa(job #1257737)

Utilizator roparexRoparex roparex Data 8 noiembrie 2014 09:59:46
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<fstream>
#include<deque>
using namespace std;
deque<int> a;
int n,x,k,i,v[5000001],mini=-300001;
long long sol;
int main()
{
    ifstream fin("secventa.in");
    ofstream fout("secventa.out");
    fin>>n>>k;
    for(i=1;i<=n;i++)
    {
        fin>>v[i];
    }
    for(i=1;i<=n;i++)
    {
        if(!a.empty()&&a.front()==i-k)
            a.pop_front();
        while(!a.empty()&&v[a.back()]>v[i])
            a.pop_back();
        a.push_back(i);
        if(i>=k&&v[a.front()]>mini) mini=v[a.front()],sol=a.back();
    }
    fout<<sol-k+1<<' '<<sol<<' '<<mini;
    return 0;
}