Cod sursa(job #1318698)

Utilizator Alex_dudeDudescu Alexandru Alex_dude Data 16 ianuarie 2015 11:50:53
Problema Heapuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <cstdio>
#include <set>
#define nmax 200010
using namespace std;
FILE *f1=fopen("heapuri.in","r"),*f2=fopen("heapuri.out","w");
multiset <int> heap;
int n,tmp[nmax],nr;
int main()
{
    fscanf(f1,"%d",&n);
    for(int i=1;i<=n;i++)
    {
        int opt;
        fscanf(f1,"%d",&opt);
        if(opt==1)
        {
            int x;
            fscanf(f1,"%d",&x);
            tmp[++nr]=x;
            heap.insert(x);
        }
        else if(opt==2)
        {
            int x;
            fscanf(f1,"%d",&x);
            heap.erase(tmp[x]);
        }
        else
            fprintf(f2,"%d\n",*heap.begin());
    }
    fclose(f1);
    fclose(f2);
    return 0;
}

//Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.