Cod sursa(job #2624863)

Utilizator filiptudose2007Tudose Filip filiptudose2007 Data 5 iunie 2020 15:57:09
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
using namespace std;
priority_queue <int,vector<int>,greater<int>> h;
int n,k,v[500005];
int sel[300005];
int p;
int main()
{
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1; i<=n; ++i)
    {
        cin>>v[i];
    }
    for(int i=1; i<k; ++i)
    {
        h.push(v[i]);
        sel[v[i]+30000]++;
    }
    int poz=0,Max=INT_MIN;
    for(int i=k; i<=n; ++i)
    {
        h.push(v[i]);
        sel[v[i]+30000]++;
        while(!sel[h.top()+30000])
        {
            h.pop();
        }
        int nr=h.top();
        if(nr>Max)
        {
            Max=nr;
            poz=i;
        }
        sel[v[i-k+1]+30000]--;
    }
    cout<<poz-k+1<<' '<<poz<<' '<<Max<<'\n';
    return 0;
}