my code shows wrong answer when submitting but default inputs works fine … why ?
Hostel visit wrong answer
@ejazsaifi70
Use long long int instead of int. This is because while the values provided in the problem can be stored in int , we will be computing the sums of products. These values will become large and are likely to exceed the range of int.
Bhai,…even after changes the data type , code give wrong answer…
Can you plz edit my code…
@ejazsaifi70
While pushing a new element into the heap , you are not comparing it with the top element at all. You are simply pushing any element you get , doesn’t matter whether if its worth keeping or not.
If pq.size() < k , then simply push.
However in the else condition , only push the new distance into the heap if dist < pq.top() . Otherwise skip it and do nothing with it.
bhai, still one test case shows wrong answer
check my updated code https://ide.codingblocks.com/s/122085
@ejazsaifi70
As I mentioned in my previous reply , use long long int. long int does not make any difference.
Range of long int is same as int. Range of long long int is much larger than int and that is what we should use.
Change data type for priority queue to long long int. Also change the data type of variables x and y since you have defined them as int. If a vaiable is declared as int , its computations are done as int only and hence it would produce a wrong result.