How to Handle TLE

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());
		}
	}

}

here is your corrected code


if this solves your doubt please mark it as resolved :slight_smile: