My code goes here: https://ideone.com/udpGyd
Getting wrong on every test case and sampple test case as well
your approach is not completely correct
it’s a good try
you have to store i as well as j index of array in priority queue
you can see this Reference Code
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved 
Yes, I know we can solve that way, what I was trying to do was to make a custom class and implementing priority queue over it. If you can help me in that please elaborate.
okay
making priority queue and custom comparator is okay
you can do like this also
but the problem is you are storing only element and it’s j cordinate in priority_queue not ith cordinate this is the mistake
i have done all required changes in your code you can see it below
Modified Code
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like
: and don’t forgot to mark doubt as resolved 
Yes, I got it now, code is working.