If I write this
ans+=st.top().first;
my program runs fine but if I replace it with this
ans = ans + st.top().first;