双指针算法
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
typedef long long ll;
typedef pair<int,int>PII;
vector<PII>v(N),v1(N);
int n,a,b;
int main()
{
cin>>n>>a>>b;
for(int i=1;i<=a;i++)
{
int x,y;
cin>>x>>y;
v[i]={x,y};
}
for(int i=1;i<=b;i++)
{
int x,y;
cin>>x>>y;
v1[i]={x,y};
}
ll sum=0;
int i=1,j=1;
while(i<=a&&j<=b)
{
if(v[i].first!=v1[j].first)
{
while(v[i].first!=v1[j].first&&i<=a&&j<=b)
{
if(v[i].first<v1[j].first) i++;
else j++;
}
}
if(i<=a&&j<=b) sum+=(ll)v[i].second*v1[j].second;
i++,j++;
}
cout<<sum<<endl;
return 0;
}