Cod sursa(job #688418)

Utilizator attila3453Geiszt Attila attila3453 Data 23 februarie 2012 16:05:48
Problema Heapuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

ifstream fi("heapuri.in");
ofstream fo("heapuri.out");

struct st
{
    int nr, ord;
    st(){}
    st(int a, int b) { nr = a; ord =b; }
};

bool cmp(st a, st b)
{
    return a.nr < b.nr;
}

vector<st> a;

int main()
{
	int n, i, q, k, o, j;

	fi>>n;

	o = 0;

	for(i = 1;i <= n;i++)
	{
		fi>>q;

		if(q == 1)
		{
			fi>>k;
			o++;
			a.push_back(st(k, o));
			sort(a.begin(), a.end(), cmp);
			continue;
		}

		if(q == 2)
		{
			fi>>k;
			for(j = 0;j < (signed)a.size();j++)
                if(a[j].ord == k)
                {
                    a.erase(a.begin() + j);
                    break;
                }
            continue;
		}

		if(q ==3)
			fo<<a[0].nr<<'\n';
	}
}