Skip to content

Instantly share code, notes, and snippets.

@luccasiau
Created May 17, 2015 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luccasiau/1c28551ffe014a78527b to your computer and use it in GitHub Desktop.
Save luccasiau/1c28551ffe014a78527b to your computer and use it in GitHub Desktop.
//
// malabarismo_de_malter.cpp
//
// Created by Lucca Siaudzionis on 17/05/15.
//
// Malabarismo de Malter - Noic
#include <queue>
#include <cstdio>
using namespace std;
//------------------------
int n;
priority_queue<int> heap;
//------------------------
/*
OBS:
Se quiser declarar uma min heap ao invés de uma max heap, declare assim:
priority_queue< int, vector<int>, greater<int> > heap;
*/
int main(){
scanf("%d", &n);
for(int i = 1;i <= n;i++){
char operacao;
scanf(" %c", &operacao);
if(operacao == 'I'){ // inserir um número
int valor;
scanf("%d", &valor);
heap.push(valor);
}
if(operacao == 'D'){
printf("%d\n", heap.top()); // imprime o valor do topo
heap.pop();
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment