Whats Wrong with my code

import java.util.*;
public class Main
{

public static void main(String[] args)
{
	Scanner sc = new Scanner(System.in);
	int numCases = sc.nextInt();
	int k = sc.nextInt();
	PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
	long KthValue = Integer.MAX_VALUE;
	
	for (int i = 1; i <= numCases; i++)
	{

		int type = sc.nextInt();
		if (type == 1)
		{
			int x = sc.nextInt();
			int y = sc.nextInt();
			long dist = (x * x) + (y * y);
			if (pq.size() >= k)
			{
				if (pq.peek() > dist)
				{
					pq.poll();
					pq.add(dist);
				}
			} else
			{
				pq.add(dist);
			}
			
		} else
		{
			System.out.println(pq.peek());
		}
	}
	sc.close();
}

}

@shahid.dhariwala,
https://ide.codingblocks.com/s/229429 corrected code.

Use long instead of int everywhere.

1 Like

thanks bro :slight_smile:

1 Like