import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class PD{
int data;
int pri;
PD(int d,int p){
data=d;
pri=p;
}
}
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Comparator<PD> comparator = (e1,e2) -> {
return Integer.compare(e2.pri,e1.pri);
};
PriorityQueue<PD> pq = new PriorityQueue<>(comparator);
for (int i = 0; i < n; i++) {
int data = sc.nextInt();
int priority = sc.nextInt();
pq.add(new PD(data, priority));
}
// Access element and priority separately while peeking/popping
while (!pq.isEmpty()) {
PD topElement = pq.poll();
System.out.println("Element with highest priority: " + topElement.data + " (priority: " + topElement.pri + ")");
}
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: