Cod sursa(job #959974)

Utilizator andi23roscaRosca Andrei andi23rosca Data 9 iunie 2013 14:57:15
Problema Heapuri Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f("heapuri.in");
ofstream g("heapuri.out");
long long int v[200010],p[200010],x,y,i,j,k,n,nr=0,poz,aux;
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
if(x==1)
{
    f>>y;
    nr++;
    p[nr]=y;
    v[nr]=y;
    poz=nr;
    for(j=nr/2;j>=1;j--)
    {
        if(v[poz]<v[j])
        {
            aux=v[j];
            v[j]=v[poz];
            v[poz]=aux;
            poz=j;
        }
    }

}
if(x==2)
{
    f>>y;
    for(j=1;j<=nr;j++)
    {
        if(p[y]==v[j])  {k=j; }
    }

    for(j=k;j<nr;j++)
    {
        v[j]=v[j+1];
    }

    nr--;


    poz=nr;
    for(j=nr/2;j>=1;j--)
    {
        if(v[poz]<v[j])
        {
            aux=v[j];
            v[j]=v[poz];
            v[poz]=aux;
            poz=j;
        }
    }
}
if(x==3)
{
    g<<v[1]<<endl;
}


}

return 0;
}