Showing TLE in first test case

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
PriorityQueue hp1 = new PriorityQueue();

	int Q = scn.nextInt();
	int k = scn.nextInt();
	while (Q > 0) {
		int q = scn.nextInt();
		if (q == 1) {
			int a = scn.nextInt();
			int b = scn.nextInt();
			int sum = (a * a) + (b * b);
			hp1.offer(sum);
		} else {
			
			ArrayList<Integer> list=new ArrayList<>();
			for(int i=0;i<k-1;i++){
				list.add(hp1.poll());
			}
			System.out.println(hp1.peek());
			for(int i=0;i<list.size();i++){
				hp1.offer(list.get(i));
			}
			
		}

		Q--;
	}

}

}

@guptadev354,
Corrected code: https://ide.codingblocks.com/s/223954

For every query of type 1, insert elements until the size of the heap becomes β€˜k’.
Then for every query of type 1 after reaching the size k for heap(max-heap) we will check if the current element is smaller than the root of the heap or not. If it is not smaller then we ignore it else we remove the root of the heap and push the new element in the heap. (What this will do is maintain a heap of size k which will contain k nearest coordinates for the dean) .
For every query of type 2 just print the root of the heap.

you don’t have to use arraylist here, also use long instead of int.