Cod sursa(job #3324781)

Utilizator Luca_georgescuLuca Georgescu Luca_georgescu Data 23 noiembrie 2025 14:30:58
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("secventa.in");
ofstream g("secventa.out");

int n,k;

int main()
{
    f >> n >> k;

    priority_queue <int, vector<int>, greater<int> > pq;
    int rez=-1;

    for (int i=1; i<=n; i++ )
    {
        int x; f >> x;
        pq.push(x);

        if ( pq.size()==k )
        {
            rez=max(rez,pq.top());
            pq.pop();
        }
    }

    g << rez;
    return 0;
}