@srishti34
Heyy,
plzz refer my c++ solution . I have used min heap and max heap concept.
Let me know if u get stuck at any point.
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
priority_queue<int> y;
priority_queue<int,vector<int>,greater<int>> o;
int n,a,b;
cin>>n;
int smo=0,smy=0;
unordered_map<int,int> mp;
for(int i=0;i<n;i++)
{
cin>>a>>b;
mp[a]=b;
if(i%2==0)
{
o.push(a);
smo+=mp[a];
smo-=mp[o.top()];
y.push(o.top());
smy+=mp[o.top()];
o.pop();
}
else
{
y.push(a);
smy+=mp[a];
smy-=mp[y.top()];
o.push(y.top());
smo+=mp[y.top()];
y.pop();
}
cout<<abs(smo-smy)<<endl;
}
return 0;
}