Cod sursa(job #2295448)

Utilizator isav_costinVlad Costin Andrei isav_costin Data 3 decembrie 2018 17:50:05
Problema Heapuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <cstdio>
#include <set>

using namespace std;

struct Lapte
{
  int k;
  int vechime;
};

struct cmp
{
  bool operator() ( const Lapte &a, const Lapte &b )
  {
    return a.k<b.k;
  }
};

multiset<Lapte,cmp> h;

inline void elimina( int v )
{
  for( auto i : h )
    if( i.vechime==v )
    {
      h.erase(i);
      break;
    }
}

int main()
{
  freopen( "heapuri.in", "r", stdin );
  freopen( "heapuri.out", "w", stdout );

  int n, v=0, q, x;

  scanf( "%d", &n );

  while( n )
  {
    scanf( "%d", &q );

    if( q==1 )
    {
      scanf( "%d", &x );

      h.insert(Lapte{x,++v});
    }
    else
      if( q==2 )
      {
        scanf( "%d", &x );

        elimina(x);
      }
      else
        printf( "%d\n", h.begin()->k );

    n--;
  }

  return 0;
}