Priority in pair inside priority_queue on basis of both elements
This test is wrong:

return a.first &gt; b.first &amp;&amp; a.second&lt;b.second;


Try:

return a.first &gt; b.first || (a.first == b.first &amp;&amp; a.second &lt; b.second)


Some other things

This is not a legal header

#include&lt;bits/stdc++.h&gt;


Remove this immediately your code is invalid with it there.

Never do this:

using namespace std;


Its a bad habit that will cause you problems in real code. Always pre-fix things from the standard library with std:: (Its short for a reason). 

see: https://stackoverflow.com/q/1452721/14065

Use menaingful variable names.

Names like i n m have no meaning. Also when you have longer code searching the source for them will turn up a lot of false negatives thus making it harder to keep your code working.

Prefer prefix ++ over the postfix version.

    for(int i=0;i&lt;n;i++)

    for(int loop = 0; loop &lt; inputElementCount; ++loop)


A bit of white space makes things easier to read.

        cin&gt;&gt;a&gt;&gt;b;

        // Why not
        std::cin &gt;&gt; value1 &gt;&gt; value2;


When poping from a queue you should check its not empty not assume it has a particular size:

for(;!queue.empty(); queue.pop())
{
    auto const&amp; item = queue.top();
    std::cout &lt;&lt; item.first &lt;&lt; " " &lt;&lt; item.second &lt;&lt; "\n";
}