Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created February 27, 2014 09:54
Show Gist options
  • Save KT-Yeh/9247274 to your computer and use it in GitHub Desktop.
Save KT-Yeh/9247274 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <map>
using namespace std;
int main()
{
map<int,int> Map;
int instruction, priority, number;
while (scanf("%d", &instruction)) {
switch (instruction) {
case 1:
scanf("%d%d", &number, &priority);
Map[priority] = number;
break;
case 2:
if (Map.empty()) puts("0");
else {
printf("%d\n", (--Map.end())->second);
Map.erase(--Map.end());
}
break;
case 3:
if (Map.empty()) puts("0");
else {
printf("%d\n", Map.begin()->second);
Map.erase(Map.begin());
}
break;
case 0:
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment