n=int(input())
d=dict()
for i in range(n):
x,y=map(int,input().split())
d[x]=y
m=int(input())
for i in range(m):
x,y=map(int,input().split())
if x in d:
d[x]=max(y,d.get(x))
else:
d[x]=y
print(sum(d.values()))
#include <bits/stdc++.h>
using namespace std;
#define ll long long
map <ll, pair<ll, ll> > m;
int main() {
ll n;
cin >> n;
ll a[n], x[n];
ll ans = 0;
for(ll i = 0; i < n; i++) {
cin >> a[i] >> x[i];
ans += x[i];
m[a[i]] = make_pair(1, x[i]);
}
ll q;
cin >> q;
ll b[q], y[q];
for(ll i = 0; i < q; i++) {
cin >> b[i] >> y[i];
if(m[b[i]].first == 1) {
if(y[i] > m[b[i]].second) {
ans -= m[b[i]].second;
ans += y[i];
}
}
else {
ans += y[i];
}
}
cout << ans;
}
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |
Missing numbers | Maximum sum |
13 Reasons Why | Friend's Relationship |