Below is my codeā¦last test case time outā¦pls resolve==>>
public static void main(String[] args) {
PriorityQueue< Long > pq = new PriorityQueue<>(Collections.reverseOrder());
Scanner input= new Scanner(System.in);
int queries = input.nextInt();
int k = input.nextInt();
while (queries-- > 0) {
int type = input.nextInt();
if(type == 1) {
long x = input.nextLong();
long y = input.nextLong();
long dist = (x*x + y*y);
if(pq.size() < k) {
pq.add(dist);
} else {
if(pq.peek() > dist) {
pq.poll();
pq.add(dist);
}
}
} else {
System.out.println(pq.peek());
}
}
}
